2dRogueLike源码分析Player

1.调用unity包using UnityEngine;using System.Collections;using UnityEngine.SceneManagement; //Allows us to use SceneManager2.继承MovingObject   属性:重载level的延迟,food的点数,soda的点数,对wall的伤害,animator,food总数 ...
摘要由CSDN通过智能技术生成

1.调用unity包

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;      //Allows us to use SceneManager

2.继承MovingObject

   属性:重载level的延迟,food的点数,soda的点数,对wall的伤害,animator,food总数

    //Player inherits from MovingObject, our base class for objects that can move, Enemy also inherits from this.
    public class Player : MovingObject
    {
        public float restartLevelDelay = 1f;        //Delay time in seconds to restart level.
        public int pointsPerFood = 10;              //Number of points to add to player food points when picking up a food object.
        public int pointsPerSoda = 20;              //Number of points to add to player food points when picking up a soda object.
        public int wallDamage = 1;                  //How much damage a player does to a wall when chopping it.
        
        
        private Animator animator;                  //Used to store a reference to the Player's animator component.
        private int food;                           //Used to store player food points total during level.

3.重写Start函数

   获取player的animator

   从GameManager获取全局food值

   调用父类的start函数

        //Start overrides the Start function of MovingObject
        protected override void Start ()
        {
            //Get a component reference to the Player's animator component
            animator = GetComponent<Animator>();
            
            //Get the current food point total stored in GameManager.instance between levels.
            food = GameManager.instance.playerFoodPoints;
            
            //Call the Start function of the MovingObject base class.
            base.Start ();
        }

4.更新全局playerfood的值

        //This function is called when the behaviour becomes disabled or inactive.
        private void OnDisable ()
        {
            //When Player object is disabled, store the current local food total in the GameManager so it can be re-loaded in next level.
            GameManager.instance.playerFoodPoints = food;
        }

5.如果不是player的回合&#x

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值