Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manjitbedi/controller
Playground for using controllers with Unity
https://github.com/manjitbedi/controller
unity
Last synced: 9 days ago
JSON representation
Playground for using controllers with Unity
- Host: GitHub
- URL: https://github.com/manjitbedi/controller
- Owner: ManjitBedi
- Created: 2023-04-24T00:18:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-22T16:49:42.000Z (8 months ago)
- Last Synced: 2024-11-08T20:34:48.355Z (2 months ago)
- Topics: unity
- Language: C#
- Homepage:
- Size: 4.52 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Controller - playground for using controllers with Unity
Note: there are bugs in the code - to be fixed!
I am using the project to try out working with controllers with Unity; so far all of the projects that I have worked on used touches on mobile devices or mouse input & keyboard input on desktops.
Now it is time to try out using controllers.
Initially, I am developing on MacOs with a Xbox controller connected over BlueTooth - woot.
The simple game is using an Action map already provided with some sample code from Unity.
The code will take the direction values from a gamepad or the WASD keys and trigger an event callback.
```
public void OnMove(InputAction.CallbackContext context)
{
// read the value for the "move" action each event call
moveAmount = context.ReadValue();
movementText.text = $"({moveAmount.x.ToString("F2")}, {moveAmount.y.ToString("F2")})";
}
```The movement callback is associated with a PlayerInput instance in the game scene under "Events" -> "gamePlay".
## Collision detection
- the simple mechanic of the game level is to register a hit of a falling object with the player game object.
- this requires the falling objects to have the 'is trigger' property set to true; we don't need to use physics with the objects bouncing off of each other
- also for collisions to register the player and dropping game objects need colliders & rigid body components
- the score is updated if the tag of the object collided with is "Spawned"```
///
/// Upon collision with another game object, increase the score.
///
///
private void OnTriggerEnter(Collider other)
{
// Check for a match with the specific tag on any GameObject that collides with your GameObject
if (other.gameObject.tag == "Spawned")
{
score += 10;
scoreText.text = $"Score: {score.ToString("D5")}";
StartConsumeItemSequence(other.gameObject);
}
}
```## Assets in use
This project is using:
- for animation [DOTween](http://dotween.demigiant.com)
- Assets from Everything Library © David OReilly [Everything](https://www.davidoreilly.com/library)
- a some backgrounds generated by [Dream Studio](https://beta.dreamstudio.ai/generate)
- font ["Press Start 2P"](https://fonts.google.com/specimen/Press+Start+2P)