コード例 #1
0
    void pointTo(EnemyCode nextTarget)
    {
        Vector2    v     = nextTarget.transform.position - this.transform.position;
        float      angle = Mathf.Atan2(v.y, v.x) * Mathf.Rad2Deg;
        Quaternion rot   = Quaternion.AngleAxis(angle - 90, Vector3.forward);

        transform.rotation = Quaternion.Slerp(transform.rotation, rot, turnSpeed * Time.deltaTime);
    }
コード例 #2
0
    void FixedUpdate()
    {
        EnemyCode nextTarget = getNextTarget();

        if (nextTarget != null)
        {
            pointTo(nextTarget);
            shoot();
        }

        checkForDeath();
    }
コード例 #3
0
 EnemyCode[] GetEnemyCode()
 {
     Object[]    g = FindObjectsOfType(typeof(EnemyCode));
     EnemyCode[] t = new EnemyCode[g.Length];
     for (int h = 0; h < g.Length; h++)
     {
         EnemyCode temp = (EnemyCode)g[h];
         if (!temp.color.Equals(this.color))
         {
             t[h] = temp;
         }
         else
         {
             t[h] = null;
         }
     }
     return(t);
 }
コード例 #4
0
    Color32 getRandomColor()
    {
        Color32 temp    = new Color32();
        int     randNum = (Random.Range(0, 255) / 50) * 50;

        switch (Random.Range(1, 6))
        {
        case 1: temp.r = (byte)randNum; temp.b = 0xFF; temp.g = 0x0; temp.a = 0xFF; break;

        case 2: temp.r = 0x0; temp.b = (byte)randNum; temp.g = 0xFF; temp.a = 0xFF; break;

        case 3: temp.r = 0xFF; temp.b = 0x0; temp.g = (byte)randNum; temp.a = 0xFF; break;

        case 4: temp.r = (byte)randNum; temp.b = 0x0; temp.g = 0xFF; temp.a = 0xFF; break;

        case 5: temp.r = 0xFF; temp.b = (byte)randNum; temp.g = 0x0; temp.a = 0xFF; break;

        case 6: temp.r = 0x0; temp.b = 0xFF; temp.g = (byte)randNum; temp.a = 0xFF; break;
        }

        Object[] g  = FindObjectsOfType(typeof(EnemyCode));
        Object[] g2 = FindObjectsOfType(typeof(Controler));
        for (int c = 0; c < g.Length; c++)
        {
            EnemyCode e = (EnemyCode)g[c];
            if (temp.ToString().Equals(e.color))
            {
                return(getRandomColor());
            }
        }
        for (int c = 0; c < g2.Length; c++)
        {
            Controler e = (Controler)g2[c];
            if (temp.ToString().Equals(e.color))
            {
                return(getRandomColor());
            }
        }

        return(temp);
    }
コード例 #5
0
    EnemyCode getNextTarget()
    {
        EnemyCode[] t          = GetEnemyCode();
        EnemyCode   nextTarget = null;
        float       dist       = Mathf.Infinity;

        for (int h = 0; h < t.Length; h++)
        {
            if (t[h] != null)
            {
                float d = Vector3.Distance(this.transform.position, t[h].transform.position);

                if (nextTarget == null || d < dist)
                {
                    nextTarget = t[h];
                    dist       = d;
                }
            }
        }
        return(nextTarget);
    }