예제 #1
0
    // Update is called once per frame
    void Update()
    {
        int countWP = path.GetCount();

        if (countWP < 1)
        {
            return;
        }
        if ((internalTime + startTime) > Time.fixedTime)
        {
            return;
        }
        if (firstFrame)
        {
            transform.position = path.GetPoint(currentStart);
            firstFrame         = false;
            //  Debug.Log("firstFrame" + Time.fixedTime);
        }
        {
            start     = path.GetPoint(currentStart);
            end       = path.GetPoint(currentEnd);
            direction = (end - start).normalized;
            distance  = (end - transform.position).magnitude;

            if (distance > 1)
            {
                transform.position += direction * Time.deltaTime * speed;
                transform.LookAt(end);
            }
            else
            {
                if (currentEnd < path.GetCount() - 2)
                {
                    currentEnd++;
                    currentStart++;
                }
                else
                {
                    // currentEnd = 1;
                    // currentStart = 0;
                    //  transform.position = path.GetPoint(currentStart);
                    Destroy(gameObject, 1);
                    if (!reachBase)
                    {
                        reachBase = true;
                        PlayerController pc = PlayerController.GetPlayerController();
                        pc.BaseLifePoints -= 1;
                    }
                }
            }
        }
    }
예제 #2
0
 void SpawnWave(int waveType, int num, int startTime, float freq, TDPath path)
 {
     for (int i = 0; i < num; i++)
     {
         FollowPath FollowPath = GameObject.Instantiate(UnitsModels[waveType], path.GetPoint(0), Quaternion.identity);
         FollowPath.startTime = startTime + freq * i;
         FollowPath.gameObject.SetActive(true);
         instances.Add(FollowPath.gameObject);
         LifeIndicator lifeIndicator = FollowPath.gameObject.GetComponentInChildren <LifeIndicator>();
         if (lifeIndicator)
         {
             Enemy enemyObject = FollowPath.gameObject.GetComponent <Enemy>();
             lifeIndicator.root = enemyObject;
         }
     }
 }