示例#1
0
    void SpawnGhost(PlayerTrain playerTrain, Vector3 side)
    {
        GhostInfo  info     = new GhostInfo();
        GameObject newGhost = Instantiate(ghostPrefab) as GameObject;

        newGhost.GetComponent <GhostController> ().feature = this;
        info.obj = newGhost;
        int wagonsCount = 0;

        for (int childIndex = 0; childIndex < playerTrain.transform.childCount; childIndex++)
        {
            if (playerTrain.transform.GetChild(childIndex).GetComponent <WagonScript>() != null)
            {
                wagonsCount += 1;
            }
        }

        WagonScript wagon      = null;
        Transform   spawnPoint = null;

        for (int wagonIndex = 0; wagonIndex < wagonsCount; wagonIndex++)
        {
            // try to get random wagon point
            wagon      = playerTrain.GetWagon(Random.Range(0, wagonsCount));
            spawnPoint = wagon.GetGhostPoint();
            if (spawnPoint != null)
            {
                info.wagonIndex = wagon.GetIndex();
                break;
            }


            wagon      = playerTrain.GetWagon(wagonIndex);
            spawnPoint = wagon.GetGhostPoint();
            if (spawnPoint != null)
            {
                info.wagonIndex = wagon.GetIndex();
                break;
            }
        }
        //GameObject wagon = playerTrain.GetWagon (Random.Range(0,wagonsCount)).gameObject;
        if (spawnPoint == null)
        {
            return;
        }

        newGhost.transform.parent           = spawnPoint;
        newGhost.transform.localPosition    = new Vector3(0, 0, 0);
        newGhost.transform.localScale       = new Vector3(1, 1, 1);
        newGhost.transform.localEulerAngles = side;
        newGhost.GetComponent <Animator>().Play("move");

        spawnedGhosts.Add(info);
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(1))
        {
            mousePosition1 = Input.mousePosition;
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                hitPoint = new Vector3(hit.point.x, 0.4f, hit.point.z);
            }
            if (flag)
            {
                GameObject.Destroy(flag);
            }
            flag = Instantiate(flag, hitPoint, new Quaternion(0, 0, 0, 0));
            int i = 0;
            int n = 0;
            int w = 0;
            int x = 0;
            int y = 0;
            while (i < hitColliders.Length)
            {
                // if (Physics.Raycast(ray, out hit)) {
                //  if (hit.transform.tag == "Wagon" && hitColliders [i].tag == "Unit") {
                //      UnitScript u = hitColliders [i].GetComponent<UnitScript> ();
                //      u.collecting = true;
                //      u.moving = false;
                //      u.attacking = false;
                //  } else if (hit.transform.tag == "Enemy" && hitColliders [i].tag == "Unit") {
                //      UnitScript u = hitColliders [i].GetComponent<UnitScript> ();
                //      u.collecting = false;
                //      u.moving = false;
                //      u.attacking = true;
                //  }
                // } else
                if (hitColliders [i].tag == "Unit")
                {
                    x     = n % width;
                    y     = n / width;
                    Point = new Vector3(hitPoint.x + (x * spacing), 0.1f, hitPoint.z + (y * spacing));
                    UnitScript u = hitColliders [i].GetComponent <UnitScript> ();
                    u.hitPoint   = Point;
                    u.collecting = false;
                    u.moving     = true;
                    u.attacking  = false;
                    i++;
                    n++;
                }
                else
                {
                    x     = -2;
                    y     = w;
                    Point = new Vector3(hitPoint.x + (x * spacing), 0.1f, hitPoint.z + (y * spacing * 3));
                    WagonScript u = hitColliders [i].GetComponent <WagonScript> ();
                    u.hitPoint = Point;
                    u.moving   = true;
                    i++;
                    w++;
                }
            }
        }
        if (Input.GetMouseButtonDown(0))
        {
            mousePosition1 = Input.mousePosition;
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                point1 = new Vector3(hit.point.x, 0, hit.point.z);
            }
        }
        if (Input.GetMouseButton(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                point2 = new Vector3(hit.point.x, 0, hit.point.z);
            }
            if (point1.x < point2.x)
            {
                A = point1.x;
                B = point2.x;
            }
            else
            {
                A = point2.x;
                B = point1.x;
            }
            if (point1.z < point2.z)
            {
                C = point1.z;
                D = point2.z;
            }
            else
            {
                C = point2.z;
                D = point1.z;
            }
            MyCollisions();
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (hitColliders.Length != 0)
            {
                source.PlayOneShot(ready, 3.0f);
            }
        }
    }
示例#3
0
 void Update()
 {
     m_Animator.speed = 1;
     for (int i = 0; i < list.wagons.Count; i++)
     {
         if (closestWagon == null && (list.wagons [i].supply > 0 || i == list.wagons.Count - 1))
         {
             closestWagon = list.wagons [i];
             d            = Vector3.Distance(list.wagons [i].transform.position, transform.position);
         }
         else if (Vector3.Distance(list.wagons [i].transform.position, transform.position) <= d && list.wagons [i].supply > 0)
         {
             closestWagon = list.wagons [i];
             d            = Vector3.Distance(list.wagons [i].transform.position, transform.position);
         }
     }
     transform.eulerAngles += new Vector3(-90, 0, 0);
     if (attacking)
     {
         m_Animator.SetBool("isAttacking", true);
         m_Animator.SetBool("isWalking", false);
         attackTimer -= Time.deltaTime;
         if (attackTimer <= 0.0f)
         {
             attacking   = false;
             attackTimer = 1.0f;
         }
     }
     else if (collecting && !moving)
     {
         agent.SetDestination(closestWagon.transform.position);
         m_Animator.SetBool("isWalking", true);
         m_Animator.SetBool("isAttacking", false);
     }
     else if (Vector3.Distance(transform.position, hitPoint) >= 0.2f)
     {
         //transform.rotation = Quaternion.LookRotation(m_Rigidbody.velocity);
         m_Animator.SetBool("isWalking", true);
         m_Animator.SetBool("isAttacking", false);
         //m_Animator.speed = m_Rigidbody.velocity.magnitude / m_MoveSpeedMultiplier;
         agent.SetDestination(hitPoint);
     }
     else
     {
         m_Animator.SetBool("isWalking", false);
         m_Animator.SetBool("isAttacking", false);
         moving = false;
     }
     timer -= Time.deltaTime;
     if (timer <= 0.0f)
     {
         timerEnded();
         timer = 10.0f;
     }
     if (supply <= 5 && Vector3.Distance(closestWagon.transform.position, transform.position) <= range)
     {
         if (!moving && !attacking && closestWagon.supply >= 1)
         {
             collecting = true;
         }
     }
     if (collecting && Vector3.Distance(closestWagon.transform.position, transform.position) <= 0.5f)
     {
         while (supply < maxSupply && closestWagon.supply >= 1)
         {
             supply += 1;
             closestWagon.supply -= 1;
         }
         collecting = false;
     }
     if (health <= 0)
     {
         Destroy(gameObject);
         Destroy(redbar);
         Destroy(greenbar);
         Destroy(supplybar);
     }
 }
示例#4
0
 void Update()
 {
     for (int i = 0; i < list.wagons.Count; i++)
     {
         if (closestWagon == null)
         {
             closestWagon = list.wagons [i];
             d            = Vector3.Distance(list.wagons [i].transform.position, transform.position);
         }
         else if (Vector3.Distance(list.wagons [i].transform.position, transform.position) <= d)
         {
             closestWagon = list.wagons [i];
             d            = Vector3.Distance(list.wagons [i].transform.position, transform.position);
         }
     }
     if (d < 10.0f && d > 9.0f && !screamed && !list.scream)
     {
         list.scream = true;
         screamed    = true;
         list.fightingSource.PlayOneShot(scream, 3.0f);
         list.marchingSource.PlayOneShot(scream, 3.0f);
         list.timer2 = Random.Range(5.0f, 8.0f);
     }
     if (d <= 0.5f && !closestWagon.taken)
     {
         closestWagon.taken = true;
         taking             = true;
     }
     if (taking && Vector3.Distance(closestWagon.transform.position, transform.position) <= 0.5f)
     {
         agent.SetDestination(spawnpoint);
         agent.speed           = closestWagon.agent.speed;
         closestWagon.hitPoint = transform.position;
     }
     else
     {
         agent.SetDestination(closestWagon.transform.position);
         if (closestWagon.taken && d <= 0.5f)
         {
             agent.speed = closestWagon.agent.speed;
         }
         else
         {
             agent.speed = 1;
         }
     }
     if (health <= 0)
     {
         if (closestWagon.taken)
         {
             closestWagon.taken = false;
         }
         if (!list.death)
         {
             list.death = true;
             list.fightingSource.PlayOneShot(death1, 1.0f);
             list.marchingSource.PlayOneShot(death2, 1.0f);
             list.timer3 = Random.Range(0.5f, 1.0f);
         }
         Destroy(gameObject);
     }
 }