A sample 3D car driving project made with Unity.
Get the code from the repo or play online.
How to play is in readme or in game menu. Hit the barrier, avoid the boulder, be fast, release the rage.
Interesting notes:
- AudioSource.PlayOneShot: use this passing an AudioClip as input to play a sound file once when triggered
- Input.GetKeyDown(KeyCode): use this to determine whether the user pressed a particular key and avoid multiple triggers if the key was pressed over multiple frames
- GameObject.SetActive: parent can trigger child objects active/inactive with this, eg to swap models for same object on a certain event
- LateUpdate is invoked after Update, so if you have a follow camera, update position there to avoid jerky movement
- transform.Translate: move object (slide)
- transform.Rotate: move object (rotate)
- Vector3 has many static predefined vectors available eg: forward, up, one, zero
- Can tag objects and then check whether interaction happened with an object type looking at its tag eg: collision.gameObject.CompareTag(TAG) will be true if this object collided with TAG object
- Time.timeScale set to 0 stops game time, but can still read player inputs
- SceneManager requires import (using) UnityEngine.SceneManagement
No comments:
Post a Comment
With great power comes great responsibility