コード例 #1
0
    void Spawn()
    {
        GameObject enemy = Instantiate(prefab);

        enemy.transform.position = this.transform.position;
        enemy.transform.rotation = this.transform.rotation;

        AI.Agent2D agent = enemy.GetComponent <AI.Agent2D>();
        agent.rotation = enemy.transform.rotation.eulerAngles.z;

        if (DestroyOnSpawn)
        {
            Invoke("Destroy", DestroyDelay);
        }
    }
コード例 #2
0
    // Enemy must have Agent component
    void SetTargetOrientation(GameObject target, Transform enemy)
    {
        // Calculating rotation
        float targetOrientation = 0;

        if (target)
        {
            Vector3 direction = target.transform.position - enemy.position;
            targetOrientation  = Mathf.Atan2(direction.y, direction.x);
            targetOrientation *= Mathf.Rad2Deg;

            AI.Agent2D agent = enemy.GetComponent <AI.Agent2D>();
            if (agent)
            {
                agent.rotation = targetOrientation;
            }
            else
            {
                enemy.transform.eulerAngles = new Vector3(0, 0, targetOrientation);
            }
        }
    }
コード例 #3
0
    //TODO: Fix enemyScript.SetTarget(tempTarget);
    void SpawnEnemy(WaveEnemy waveEnemy)
    {
        Debug.Log("Spawning Enemy " + waveEnemy.enemy.name);
        Transform spawnTransform;

        spawnTransform = waveEnemy.GetRandomSpawn();

        if (spawnTransform == null)
        {
            spawnTransform = _transform;
        }

        Transform enemy = Instantiate(waveEnemy.enemy, spawnTransform.position, spawnTransform.rotation) as Transform;

        if (SetEnemyRotation)
        {
            /// Calculating rotation;
            GameObject obj = GameManager.Instance.GetPlayer(spawnTransform.position);
            float      targetOrientation = 0;
            if (obj)
            {
                Vector3 direction = obj.transform.position - spawnTransform.position;
                targetOrientation  = Mathf.Atan2(direction.y, direction.x);
                targetOrientation *= Mathf.Rad2Deg;

                AI.Agent2D agent = enemy.GetComponent <AI.Agent2D>();
                if (agent)
                {
                    agent.rotation = targetOrientation;
                }
                else
                {
                    enemy.transform.eulerAngles = new Vector3(0, 0, targetOrientation);
                }
            }
        }
    }