Beispiel #1
0
        bool IsSpaceOccupied(Selectable s, Vector3 v)
        {
            float rr = s.GetRadius() / 2.0f;

            RaycastHit[] hits = (Physics.BoxCastAll(v, new Vector3(rr, rr, rr), Vector3.right));

            bool occupied = false;

            foreach (RaycastHit hit in hits)
            {
                if (hit.transform == GameTerrain.transform)
                {
                    continue;
                }
                else
                if (hit.transform == s.transform)
                {
                    continue;
                }
                else
                {
                    occupied = true;
                }
            }
            return(occupied);
        }
Beispiel #2
0
 void Attack(Selectable sel)
 {
     foreach (Selectable t in Selection)
     {
         Vehicle v = t.GetComponent <Vehicle>();
         if (v != null)
         {
             float r = sel.GetRadius();
             v.DoSetTarget(sel.transform.position + new Vector3(UnityEngine.Random.value * r, 0, UnityEngine.Random.value * r));
         }
     }
 }
Beispiel #3
0
        void PlaceMeNear(GameObject go)
        {
            NavMeshAgent nm = go.GetComponent <NavMeshAgent>();
            Selectable   gs = go.GetComponent <Selectable>();

            gs.SnapSize = new Vector3(gs.GetRadius() * 5, 1, gs.GetRadius() * 5);
            if (nm != null)
            {
                float   r   = gs.GetRadius() * 5;
                Vector3 pos = Tools.GetSnap(go, go.transform.position + new Vector3(Random.value * r - r / 2, 0, Random.value * r - r / 2));
                go.GetComponent <NavMeshAgent>().Warp(pos);
            }
            else
            {
                gs.IsPlacing = true;
                float   r   = gs.GetRadius() * 5;
                Vector3 pos = Tools.GetSnap(go, go.transform.position + new Vector3(Random.value * r - r / 2, 0, Random.value * r - r / 2));
                go.transform.position = pos;
                gs.IsPlacing          = false;
            }

            CreateRadarDot(go);
        }
Beispiel #4
0
        void PlaceMe(GameObject go)
        {
            Random.InitState((int)(Time.frameCount));
            Selectable gs   = go.GetComponent <Selectable>();
            Team       team = GetTeamByID(gs.Data.Team);

            go.transform.parent = team.transform;

            if (gs.Data.Team == MyTeam.Data.TeamID)
            {
                team.GetComponent <LimitsMan>().CheckBuild(gs.Data.Type);
            }

            RaycastHit hit;

            Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2.5f, Screen.height / 2, 0));

            if (GameTerrain.GetComponent <Collider>().Raycast(ray, out hit, Mathf.Infinity))
            {
                NavMeshAgent nm = go.GetComponent <NavMeshAgent>();
                if (nm != null)
                {
                    float   r   = gs.GetRadius() * 5;
                    Vector3 pos = Tools.GetSnap(go, hit.point + new Vector3(Random.value * r - r / 2, 0, Random.value * r - r / 2));
                    go.GetComponent <NavMeshAgent>().Warp(pos);
                }
                else
                {
                    gs.IsPlacing = true;
                    float   r   = gs.GetRadius() * 2;
                    Vector3 pos = Tools.GetSnap(go, hit.point + new Vector3(Random.value * r - r / 2, 0, Random.value * r - r / 2));
                    go.transform.position = pos;
                }
            }

            CreateRadarDot(go);
        }