-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayerAnimate.cs
More file actions
35 lines (33 loc) · 1015 Bytes
/
playerAnimate.cs
File metadata and controls
35 lines (33 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerAnimate : MonoBehaviour {
private Animator myAnim;
public Sprite[] faceDirection;
public Sprite[] goingDirection;
public int leftIndex, rightIndex;
private SpriteRenderer mySprite;
// Use this for initialization
void Start () {
myAnim = GetComponent<Animator> ();
mySprite = GetComponent<SpriteRenderer> ();
}
// Update is called once per frame
void Update () {
if (myAnim.GetBool ("goingLeft")) {
StartCoroutine (Going (leftIndex));
}
if (myAnim.GetBool ("goingRight")) {
StartCoroutine (Going (rightIndex));
}
}
IEnumerator Going(int direction){
mySprite.sprite = faceDirection [direction];
yield return new WaitForEndOfFrame ();
while((myAnim.GetBool ("goingLeft"))||(myAnim.GetBool ("goingRight"))) {
Debug.Log ("moving");
mySprite.sprite = goingDirection [direction];
yield return new WaitForEndOfFrame ();}
mySprite.sprite = faceDirection [direction];
}
}