示例#1
0
    /// <summary>Spawn avatar if spawn point is registered</summary>
    /// <param name="playerNo">Number of the avatar to spawn</param>
    /// <param name="active">If true, the avatar is spawned active</param>
    /// <param name="allowControl">If true, the avatar is immediately controllable</param>
    public GameObject SpawnCharacter(int playerNo, bool allowControl = true)
    {
        Transform spawnTr = spawnPoints[playerNo - 1];

        if (spawnTr == null)
        {
            throw ExceptionsUtil.CreateExceptionFormat("No spawn point registered for player {0}.", playerNo);
        }

        // activate stored avatar instance and move to spawn position
        CharacterMaster avatar = m_Characters[playerNo - 1];

        avatar.gameObject.SetActive(true);
        avatar.transform.position = spawnTr.position;

        // stop control if needed (prefab should have CharacterControl active by default)
        if (!allowControl)
        {
            avatar.GetComponentOrFail <CharacterControl>().StopControl();
        }

        // update derivated counter of avatars registered and active in the scene
        remainingCharacterNb++;

        // return the spawned avatar as a game object
        return(avatar.gameObject);
    }
示例#2
0
    public void Spawn(Vector2 position)
    {
        if (IsInUse())
        {
            throw ExceptionsUtil.CreateExceptionFormat("Cannot spawn {0}, already in use.", this);
        }

        gameObject.SetActive(true);
        transform.position = position;
    }