Exemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject xObject;

        FrameRate = (1.0f / Time.deltaTime);
        // Debug.Log("Collision");
        xObject = collision.gameObject;
        if (xObject.tag == "EnemyLaser")
        {
            if (xObject != null)
            {
                int enemyLaserIndex = 0;
                enemyLaserIndex = xObject.GetComponent <enemyLaserScript>().thisEnemyLaserIndex;
                if (enemyLaserIndex != null && enemyLaserIndex >= 0)
                {
                    agent.setEnemyActive(3, enemyLaserIndex, false); /* turn laser to inactive*/
                }
            }
        }
        else if (xObject.tag == "playerLaser")
        {
            if (xObject != null)
            {
                int enemyLaserIndex = 0;
                enemyLaserIndex = xObject.GetComponent <enemyLaserScript>().thisEnemyLaserIndex;
                if (enemyLaserIndex != null && enemyLaserIndex >= 0)
                {
                    agent.setEnemyActive(2, enemyLaserIndex, false); /* turn laser to inactive*/
                }
            }
        }
        Destroy(xObject);
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        bool success;

        //Debug.Log("enemy laser from Update:" + xProjectile);

        CountDownAndShoot();
        if (Player == null || !Player.activeSelf)
        {
            agent.setEnemyActive(1, thisEnemyIndex, false); /* turn enemy to active*/
            Destroy(gameObject);

            // I'm going to destroy all enemies if the player dies disappears!
        }

        if (thisEnemyIndex >= 0)
        {
            Vector3 thisPos = transform.position;
            Vector2 TwoPos;
            TwoPos.x = thisPos.x;
            TwoPos.y = thisPos.y;
            success  = agent.setEnemyPosition(1, thisEnemyIndex, TwoPos);
            if (!success)
            {
                Destroy(gameObject);
            }
        }
    }
Exemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     shotCounter = Random.Range(minTimeBetweenShots, maxTimeBetweenShots);
     health      = StartHealth;
     //Debug.Log("enemy laser from Start:"+xProjectile);
     aKeepScore = FindObjectOfType <keepScor>();
     agent      = FindObjectOfType <LaserAgent>();
     Player     = GameObject.Find("Player");
     if (agent != null)
     {
         thisEnemyIndex = agent.getFirstAvailableEnemyIndex(1);
         if (thisEnemyIndex >= 0)
         {
             agent.setEnemyActive(1, thisEnemyIndex, true); /* turn enemy to active*/
         }
         else
         {
             Destroy(gameObject);
         }
     }
     else
     {
         Destroy(gameObject);
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (Player == null || !Player.activeSelf || agent == null)
        {
            agent.setEnemyActive(EnemyOrPlayer, thisEnemyLaserIndex, false); /* turn enemy to active*/
            Destroy(gameObject);

            // I'm going to destroy all enemies if the player dies disappears!
        }

        if (thisEnemyLaserIndex >= 0)
        {
            Vector3 thisPos = transform.position;
            Vector3 copyPos = transform.position;
            bool    success;
            Vector2 TwoPos;
            TwoPos.x = thisPos.x;
            TwoPos.y = thisPos.y;

            TwoPos.y          -= Time.deltaTime * laserSpeed;
            copyPos.x          = TwoPos.x;
            copyPos.y          = TwoPos.y;
            transform.position = copyPos;
            success            = agent.setEnemyPosition(EnemyOrPlayer, thisEnemyLaserIndex, TwoPos);
            if (!success)
            {
                Destroy(gameObject);
            }
            //    Debug.Log("laserindex:"+ thisEnemyLaserIndex+"     enemylaser positon:" + TwoPos);
        }
    }
Exemplo n.º 5
0
    public void Hit()
    {
        int enemyLaserIndex;

        Destroy(gameObject);
        enemyLaserIndex = GetComponent <enemyLaserScript>().thisEnemyLaserIndex;
        if (enemyLaserIndex != null && enemyLaserIndex >= 0)
        {
            agent.setEnemyActive(EnemyorPlayer, enemyLaserIndex, false); /* turn enemy to active*/
        }
    }
    // Use this for initialization
    void Start()
    {
        agent  = FindObjectOfType <LaserAgent>();
        Player = GameObject.Find("Player");

        if (agent != null)
        {
            thisEnemyLaserIndex = agent.getFirstAvailableEnemyIndex(EnemyOrPlayer); //use 3 for enemy laser index 2 for player.
            if (thisEnemyLaserIndex >= 0)
            {
                agent.setEnemyActive(EnemyOrPlayer, thisEnemyLaserIndex, true); /* turn enemy to active*/
            }
            else
            {
                Destroy(gameObject);
            }
        }
        else
        {
            Destroy(gameObject);
        }
    }
Exemplo n.º 7
0
 void Move()
 {
     if (wayPointIndex <= waypoints.Count - 1)
     {
         var targetPosition = waypoints[wayPointIndex].transform.position;
         //Debug.Log("current pos:" + transform.position + "   targ:" + targetPosition);
         var movementThisFrame = moveSpeed * Time.deltaTime;
         transform.position = Vector3.MoveTowards(transform.position, targetPosition, movementThisFrame);
         if (transform.position == targetPosition)
         {
             wayPointIndex++;
             //  Debug.Log("move:" + wayPointIndex);
         }
     }
     else
     {
         Destroy(gameObject);
         if (agent != null)
         {
             agent.setEnemyActive(1, thisEnemyIndex, false); /* turn enemy to inactive*/
         }
     }
 }