1. Image material import
Change the Texture Type to Sprite (2D and UI).
The atlas (one image contains multiple pictures) should set the Sprite Mode to Multiple.
2. Create animation
The easiest way is to drag all the pictures directly to the Hierarchy window, you can create animations directly.
3. Change the display of Sprite
Modify the sprite of the SpriteRenderer.
1 if (h> 0 ) 2 { 3 sr.sprite = tankSprites [ 1 ]; //右 4 } 5 else if (h < 0 ) //左 6 { 7 sr.sprite = tankSprites [ 3 ]; 8 }
4. 2D Colliders
5. FixedUpdate
Used for physical rigid body movement.
6. Euler angle to quaternion
Quaternion.Euler();
7. Trigger detection
Add BoxCollider2D and check isTrigger.
Common functions are:
1 void OnTriggerEnter2D(Collider2D other) 2 { 3 } 4 void OnTriggerExit2D(Collider2D other) 5 { 6 } 7 8 void OnTriggerStay2D(Collider2D other) 9 { 10 }
8. Delayed execution of functions
Invoke("InitPlayer", 1f);
9. Singleton Pattern
1 private static PlayerManage instance; 2 3 public static PlayerManage Instance 4 { 5 get { return PlayerManage.instance; } 6 set { PlayerManage.instance = value; } 7 } 8 9 void Awake() 10 { 11 Instance = this; 12 }
10. Load the scene
1 using UnityEngine.SceneManagement; 2 SceneManager.LoadScene("OtherSceneName",LoadSceneMode.Additive);