float maxTargetLength = 10.0f; // Maximum amount of time to have a target before searching for a new one

    void Start()
    {
        myInfo            = GetComponent <UnitInfo>();
        weaponsController = GetComponent <WeaponsController>();
        myRigidbody       = GetComponent <Rigidbody>();
        target            = GetEasiestTarget();
        myHealth          = GetComponent <Health> ();

        phase     = 1;
        shieldsOn = true;
        boosted   = false;

        if (!UnitTracker.GetActiveUnits().Contains(this.gameObject))
        {
            UnitTracker.AddUnit(this.gameObject);
        }
        // set target on spawn
        messageTxt = GameObject.Find("MessageText").GetComponent <MessageTextController>();
        messageTxt.DisplayMessage("Their shields are too strong for our weapons. Try to find a weak point.");
    }
示例#2
0
    /// <summary>
    /// Spawns a given unit type at given location with a given rotation.
    /// </summary>
    /// <param name="unitType">Type of unit to spawn.</param>
    /// <param name="spawnLocation">Location to spawn the unit.</param>
    /// <param name="spawnRotation">Rotation to spawn the unit.</param>
    /// <returns></returns>
    public static GameObject SpawnUnit(GameObject unitType, Vector3 spawnLocation, Quaternion spawnRotation)
    {
        if (unitType == null)
        {
            throw new MissingReferenceException("Given unitType was null, can't spawn.");
        }
        if (unitType.GetComponent <UnitInfo>() == null)
        {
            throw new MissingComponentException("Given unitType doesn't have a UnitInfo component. Is it a unit?");
        }
        if (unitType.GetComponent <UnitInfo>().IsPlayerShip&& UnitTracker.PlayerShip != null)
        {
            throw new System.Exception("A player ship already exists in this scene and you are trying to instantiate another player ship.");
        }

        GameObject unit;

        if (unitType.GetComponent <UnitInfo>().IsPooled)
        {
            unit = PoolController.Instance.GetObject(unitType, spawnLocation, spawnRotation);
        }
        else
        {
            unit = Instantiate(unitType, spawnLocation, spawnRotation) as GameObject;
        }

        if (unit.GetComponent <UnitInfo>().IsPlayerShip)
        {
            UnitTracker.PlayerShip = unit;
        }
        else if (!unit.GetComponent <UnitInfo>().NotTargettable)
        {
            UnitTracker.AddUnit(unit);
        }

        return(unit);
    }