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