示例#1
0
    /// <summary>
    /// Spawns this Unit. This will be called every time the Unit dies and respawns or this script is restarted.
    /// </summary>
    protected void Spawn()
    {
        // Make the GameObject visible.
        gameObject.SetActive(true);
        foreach (Transform child in transform)
        {
            child.gameObject.SetActive(true);
        }

        if (gameObject.GetComponent<RAIN.Ontology.Decoration>() == null)
        {
            gameObject.AddComponent<RAIN.Ontology.Entity>();
            RAIN.Ontology.Decoration decoration = gameObject.AddComponent<RAIN.Ontology.Decoration>();
            RAIN.Ontology.Aspect aspect = new RAIN.Ontology.Aspect(gameObject.tag, new RAIN.Ontology.Sensation("sight"));
            decoration.aspect = aspect;
        }
        if (shadow != null)
        {
            shadow.layer = gameObject.layer;
        }

        if (leader != null)
            leader.RegisterUnit(this);
        if (gameObject.tag == "Red")
            enemyName = "Blue";
        else
            enemyName = "Red";

        // Call class-specific spawn code.
        ClassSpawn();

        // Makes sure the GameObject is the right color.
        SetTeamColor();

        // Sometimes (especially when we get promoted) we run into a bug where all our variables are reset when they shouldn't be.
        if (skipSpawn)
        {
            skipSpawn = false;
            return;
        }

        // Reset all variables to their initial state.
        Debug.Log("Resetting variables on " + this);
        if (!IsPlayer())
        {
            SetOutlineColor(outlineColor);
        }
        justPromoted = false;
        ResetTarget();
        health = _maxHealth;
        if (_initialWeapon != null)
        {
            CreateWeapon(_initialWeapon);
            if (weapon != null)
            {
                weapon.gameObject.layer = gameObject.layer;
            }
        }

        Commander commander = GetCommander();
        if (commander == null)
        {
            Debug.Log(uName + "'s Commander is null!");
        }
        else
        {
            foreach (Unit unit in commander.GetAllUnits())
            {
                if (unit == this || !unit.IsAlive())
                    continue;
                Physics.IgnoreCollision(collider, unit.collider, true);
            }
            if (!(unitType == UnitType.Commander) && commander.IsAlive())
            {
                Physics.IgnoreCollision(collider, commander.collider, true);
            }
        }
        // Move it to the spawn point.
        if (spawnPoint == Vector3.zero)
        {
            if (commander != null)
            {
                spawnPoint = commander.GetSpawnPoint();
                transform.position = spawnPoint;
                if (commander.attackObjective == null)
                {
                    Vector3 ourRot = transform.rotation.eulerAngles;
                    float look = commander.transform.rotation.eulerAngles.y;
                    ourRot.y = look;
                    transform.rotation = Quaternion.Euler(ourRot);
                }
                else
                {
                    Vector3 objectivePos = commander.attackObjective.transform.position;
                    Vector3 ourRot = Quaternion.LookRotation(objectivePos - transform.position).eulerAngles;
                    float look = ourRot.y;
                    ourRot.y = look;
                    transform.rotation = Quaternion.Euler(ourRot);
                }
            }
        }

        CancelInvoke();
        timeToOurRespawn = 0.0f;
        if (!gameObject.activeInHierarchy && IsPlayer())
            Camera.main.audio.PlayOneShot(respawnBeep);

        immortal = true;
        Invoke("CanTakeDamage", RESPAWN_BLINK_TIME);
        weapon.ammo = _initialWeapon.ammo;
        // Force a recheck of any AI functions.
        HandleAI(true);
    }
示例#2
0
 private void MakeOwner()
 {
     if (owner != null && light != null)
     {
         light.color = owner.teamColor;
         if (audio != null && gameObject.GetComponent<RAIN.Ontology.Decoration>() == null)
         {
             gameObject.AddComponent<RAIN.Ontology.Entity>();
             RAIN.Ontology.Decoration decoration = gameObject.AddComponent<RAIN.Ontology.Decoration>();
             RAIN.Ontology.Aspect aspect = new RAIN.Ontology.Aspect(owner.gameObject.tag + " Gunshot", new RAIN.Ontology.Sensation("sound"));
             decoration.aspect = aspect;
         }
     }
     else
     {
         RAIN.Ontology.Decoration decoration = gameObject.GetComponent<RAIN.Ontology.Decoration>();
         if (decoration != null)
         {
             Destroy(decoration);
             Destroy(gameObject.GetComponent<RAIN.Ontology.Entity>());
         }
     }
 }