Esempio n. 1
0
 // wakes up all the drones in the scene
 void OnTriggerEnter(Collider other)
 {
     GameObject[] drones = GameObject.FindGameObjectsWithTag("Drone");
     if (!allActivated)
     {
         if (other.gameObject.tag == "Player")
         {
             foreach (GameObject d in drones)
             {
                 DroneAI dAI = d.GetComponent <DroneAI> ();
                 dAI.awake = true;
             }
             allActivated = true;
             text.text    = "Drones Activated";
         }
     }
     else
     {
         // sends a message to the drones to stop chasings
         drones = GameObject.FindGameObjectsWithTag("Drone");
         foreach (GameObject d in drones)
         {
             d.SendMessage("ResetTrigger");
         }
     }
 }
 private void OnEnable()
 {
     drone   = (DroneAI)target;
     editors = new List <Editor>();
     for (int i = 0; i < drone.behaviorData.Count; i++)
     {
         editors.Add(null);
     }
 }
Esempio n. 3
0
    void OnDestroy()
    {
        GameObject explosion = Instantiate(Exploding);

        explosion.transform.position = transform.position;
        explosion.transform.rotation = transform.rotation;

        CanCheckForEnemies     = true;
        collisionPeriodElapsed = 0.0f;

        CameraShake shake = Camera.main.gameObject.GetComponent <CameraShake>();

        if (shake != null)
        {
            shake.DoShake();
        }

        if (CanCheckForEnemies)
        {
            GameObject[] objArr = GameObject.FindGameObjectsWithTag("Enemy");
            //collisionPeriodElapsed += Time.deltaTime;
            //if (collisionPeriodElapsed < TotalCollisionPeriod) {
            for (int i = 0; i < objArr.Length; i++)
            {
                if (Vector3.Distance(objArr[i].transform.position, transform.position) < BlastRadius)
                {
                    EnemyCollisionManager collisionManager = objArr[i].GetComponent <EnemyCollisionManager>();
                    if (collisionManager != null)
                    {
                        collisionManager.DestroyEnemy();
                    }
                }
            }
            //}

            objArr = GameObject.FindGameObjectsWithTag("Drone");
            for (int i = 0; i < objArr.Length; i++)
            {
                if (Vector3.Distance(objArr[i].transform.position, transform.position) < BlastRadius)
                {
                    DroneAI droneAI = objArr[i].GetComponent <DroneAI>();
                    if (droneAI != null)
                    {
                        droneAI.Damage();
                    }
                }
            }
        }
    }
Esempio n. 4
0
    void Update()
    {
        // 크로스헤어 표시
        ARAVRInput.DrawCrosshair(crosshair);

        // 사용자가 IndexTrigger 버튼을 누르면
        if (ARAVRInput.GetDown(ARAVRInput.Button.One))
        {
            // 컨트롤러의 진동 재생
            ARAVRInput.PlayVibration(ARAVRInput.Controller.RTouch);

            // 총알 오디오 재생
            bulletAudio.Stop();
            bulletAudio.Play();

            // Ray 를 카메라의 위치로 부터 나가도록 만든다.
            Ray ray = new Ray(ARAVRInput.RHandPosition, ARAVRInput.RHandDirection);
            // Ray 의 충돌정보를 저장하기 위한 변수 지정
            RaycastHit hitInfo;
            // 플레이어 레이어 얻어오기
            int playerLayer = 1 << LayerMask.NameToLayer("Player");
            // 타워 레이어 얻어오기
            int towerLayer = 1 << LayerMask.NameToLayer("Tower");
            int layerMask  = playerLayer | towerLayer;
            // Ray 를 쏜다. ray 가 부딪힌 정보는 hitInfo 에 담긴다.
            if (Physics.Raycast(ray, out hitInfo, 200, ~layerMask))
            {
                // 총알파편효과 처리
                // 총알 이펙트 진행되고 있으면 멈추고 재생
                bulletEffect.Stop();
                bulletEffect.Play();
                // 부딪힌 지점의 방향으로 총알 이펙트 방향을 설정
                bulletImpact.up = hitInfo.normal;
                // 부딪힌 지점 바로 위에서 이펙트가 보여지도록 설정
                bulletImpact.position = hitInfo.point;

                // ray 와 부딪힌 객체가 drone 이라면 폭발효과 처리
                if (hitInfo.transform.name.Contains("Drone"))
                {
                    DroneAI drone = hitInfo.transform.GetComponent <DroneAI>();
                    if (drone)
                    {
                        drone.OnDamageProcess();
                    }
                }
            }
        }
    }
Esempio n. 5
0
    private void Update()
    {
        foreach (GameObject drone in drones)
        {
            DroneAI droneAI = drone.GetComponent <DroneAI>();
            if (Vector3.Distance(drone.transform.position, droneAI.my_path[droneAI.waypoint].point) > 25)
            {
                droneAI.my_path  = Astar(drone.transform.position, droneAI.my_goal_object.transform.position);
                droneAI.waypoint = 0;

                Color c = droneAI.my_goal_object.GetComponent <Renderer>().material.color;
                //Debug.DrawLine(startPos, goalPos, Color.black, 100f);
                drawPath(droneAI.my_path, c);
                Debug.Log("new path for drone " + droneAI.DroneID);
            }
        }
    }
    void OnTriggerEnter2D(Collider2D collider)
    {
        // Prevent enemies from colliding with one another
        if (collider.gameObject.tag != "Enemy")
        {
            DestroyEnemy();
        }

        if (gameObject.tag == "Enemy" && collider.gameObject.tag == "Friendly")
        {
            DestroyEnemy();
            Destroy(collider.gameObject);
        }

        if (gameObject.tag == "Drone" && collider.gameObject.tag == "Laser")
        {
            DroneAI droneAI = gameObject.GetComponent <DroneAI>();
            if (droneAI != null)
            {
                droneAI.Damage();
            }
        }
    }
Esempio n. 7
0
 private void Awake()
 {
     instance = GetComponent <DroneAI>();
 }
Esempio n. 8
0
 public override void InitAI()
 {
     ai = new DroneAI(this);
 }