标签:
单例:
public class GameManager : MonoBehaviour { public static GameManager _instance; private void Awake() { _instance = this; } }
碰撞(要勾选BoxCollider属性的isTrigger):
void OnTriggerEnter2D(Collider2D other) //碰撞的触发 { if(other.tag == "Enemy") //和敌人的碰撞 { if(!other.GetComponent<Enemy>().isDeath) { other.gameObject.SendMessage("BeHit"); //调用碰撞方法 } } }
每帧调用图片做动画:
//主角的运动效果(update里面调用) timer += Time.deltaTime; //int frameIndex = (int)(timer / (1f / frameCountsPersecond)); int frameIndex = (int) (timer*frameCountsPersecond); int frame = frameIndex%2; spriteRender.sprite = sprites[frame];
保存最高记录:
float historyScore = PlayerPrefs.GetFloat("historyHighScore", 0); if (nowScore > historyScore) { PlayerPrefs.SetFloat("historyHighScore", nowScore); } highScore.text = historyScore + ""; this.nowScore.text = nowScore + "";
标签:
原文地址:http://www.cnblogs.com/weishuan/p/4830887.html