Exemplo n.º 1
0
        /// <summary>
        /// Initializes the object.
        /// </summary>
        public virtual void Init()
        {
            // Initializes the weapon
            Weapon = GetComponentInChildren <Weapon>();
            if (Weapon != null)
            {
                Weapon.Init(this);
            }

            // Initializes moving
            mover = gameObject.GetOrAddComponent <TransformMover>();
            mover.Init(moveSpeed, turnSpeed);

            // Initializes turning the cannon
            TransformMover[] headMovers =
                tankHead.GetComponentsInChildren <TransformMover>();
            headMover   = headMovers[0];
            barrelMover = headMovers[1];
            headMover.Init(0f, turnSpeed);
            barrelMover.Init(0f, turnSpeed);

            // Initializes health
            Health = new Health(this, startingHealth);

            // Registers to listen to the UnitDied event
            Health.UnitDied += OnUnitDied;

            // Sets spawn position and rotation
            startPosition = transform.position;
            startRotation = transform.rotation;

            if (tankModel == null)
            {
                Debug.LogError("Tank model is not set.");
            }
        }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     _mover    = GetComponentInParent <TransformMover>();
     _myPlayer = GetComponentInParent <Tank>();
 }