예제 #1
0
    public override void OnStartServer()
    {
        base.OnStartServer();
        if (!isServer)
        {
            return;
        }
        spawnLocations = FindObjectsOfType <PhantomSpawnLocation>();
        if (spawnLocations.Length == 0)
        {
            Debug.Log("There are no spawn locations for the phantom.");
            NetworkServer.Spawn(Instantiate(phantomGameObject, Vector3.up * 2, Quaternion.identity) as GameObject);
        }
        else
        {
            int index = Random.Range(0, spawnLocations.Length - 1);
            PhantomSpawnLocation tempPos = spawnLocations[index];
            GameObject           phantom = Instantiate(phantomGameObject, tempPos.transform.position, Quaternion.identity);
            BehaviourTree        ai      = phantom.GetComponent <BehaviourTree>();
            //ai.UpdateSettings(spawnLocations[index].aiSettings());
            //ai.RestartWithoutDefaultSettings();

            NetworkServer.Spawn(phantom as GameObject);
            phantomGameObject.GetComponent <Phantom>().previousSpawnLocation = tempPos;
        }
    }
예제 #2
0
    IEnumerator Respawn(float respawnTime = 1.0f)
    {
        //setVisibility();
        gameObject.GetComponent <Rigidbody>().useGravity = false;
        gameObject.GetComponent <Rigidbody>().velocity   = Vector3.zero;
        transform.position = new Vector3(0.0f, -900000.0f, 0.0f);
        GetComponent <BehaviourTree>().enabled = false;
        GetComponent <NavMeshAgent>().enabled  = false;
        yield return(new WaitForSeconds(respawnTime));

        PhantomSpawnLocation spawnLoc = previousSpawnLocation;

        do
        {
            if (respawnPoints.Length == 1)
            {
                break;
            }
            spawnLoc = respawnPoints[Random.Range(0, respawnPoints.Length)];
        } while (spawnLoc == previousSpawnLocation);

        previousSpawnLocation = spawnLoc;
        transform.position    = spawnLoc.transform.position;

        gameObject.GetComponent <Rigidbody>().useGravity = true;
        GetComponent <Health>().currentHealth            = GetComponent <Health>().health;
        GetComponent <BehaviourTree>().enabled           = true;
        GetComponent <NavMeshAgent>().enabled            = true;
    }