码迷,mamicode.com
首页 > 编程语言 > 详细

unity笔记

时间:2015-09-23 00:57:51      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

单例:

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 + "";

 

unity笔记

标签:

原文地址:http://www.cnblogs.com/weishuan/p/4830887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!