Beispiel #1
0
    void Shoot()
    {
        // Play muzzle flash attached to gun
        muzzleFlash.Play();
        //gunSound.Play();
        FindObjectOfType <AudioManager>().Play("GunFire");
        --clipAmmo;

        // Create a Raycast from the camera, forwards, named hit, with the range var
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            // If it hits, tell what was hit, pass damage to
            // the takeDamage method from target.cs
            Debug.Log(hit.transform.name);
            TargetHealth target = hit.transform.GetComponent <TargetHealth>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }

            // If a rigidbody was hit, add a force to it.
            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }
            // Add the impact effect where the raycast impacts, and destroy
            // the effect after 2 seconds.
            GameObject impactGo = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGo, 2f);
        }
    }
Beispiel #2
0
    TargetHealth FindTarget()
    {
        float minDistance = 999;
        int   minIndex    = -1;

        for (int i = 0; i < gController.targets.Length; i++)
        {
            if (gController.targets [i].CompareTag("MyBuilding"))
            {
                continue;
            }
            TargetHealth targetHealth = gController.targets [i].GetComponent <TargetHealth> ();
            if (targetHealth == null || targetHealth.currentHealth <= 0)
            {
                continue;
            }
            float dist = Vector3.Distance(currentTransform.position, (gController.targets[i] as GameObject).transform.position);
            if (minDistance >= dist)
            {
                minDistance = dist;
                minIndex    = i;
            }
        }

        if (minIndex > -1)
        {
            return(gController.targets [minIndex].GetComponent <TargetHealth>());

            Debug.Log("[TankAutoPilot] (FindTarget) Target Name : " + currentTarget.gameObject.name);
        }
        else
        {
            return(null);
        }
    }
Beispiel #3
0
 void Start()
 {
     move         = GetComponent <Move>();
     playerInput  = GetComponent <PlayerInput>();
     animator     = GetComponentInChildren <Animator>();
     attack       = GetComponent <Attack>();
     Inv          = GetComponent <InventoryManager>();
     targetHealth = GetComponent <TargetHealth>();
 }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        fireTimer += Time.deltaTime;

        TargetHealth newTarget = null;

        if (currentTarget == null || currentTarget.currentHealth <= 0)
        {
            newTarget = FindTarget();
            if (newTarget == null)
            {
                nav.enabled = false;
                //Debug.Log ("Game End");
            }
        }

        if (newTarget != null && newTarget != currentTarget)
        {
            currentTarget = newTarget;
            float distanceToTarget = Vector3.Distance(currentTransform.position, currentTarget.transform.position);
            if (_isTargetInRange && distanceToTarget > fireRange)
            {
                _isTargetInRange = false;
            }
        }

        if (currentTarget != null && currentTarget.currentHealth > 0 && _isTargetInRange == false)
        {
            float distanceToTarget = Vector3.Distance(currentTransform.position, currentTarget.transform.position);
            if (distanceToTarget <= fireRange)
            {
                _isTargetInRange = true;
            }
        }

        if (_isTargetInRange)
        {
            if (fireTimer >= fireSpeed)
            {
                Shoot();
            }
            //Debug.Log ("[TankAutoPilot] (Update) Target in Range!!");
        }
        else
        {
            if (currentTarget != null && currentTarget.currentHealth > 0)
            {
                nav.SetDestination(currentTarget.transform.position);
            }
            else
            {
                _isTargetInRange = false;
                //Debug.Log ("[TankAutoPilot] (Update) No currentTarget!!");
            }
        }
    }
Beispiel #5
0
    void shoot()
    {
        RaycastHit hit;

        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range))
        {
            TargetHealth target = hit.transform.GetComponent <TargetHealth>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }
            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }
        }
    }
Beispiel #6
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == player)
        {
            if (levelEnd)
            {
                timer.EndTimer();

                ToggleState(false, false);

                if (nextStage)
                {
                    nextStage.ToggleState(false, true);
                }
            }
            else
            {
                if (timeTrial && !timer.IsRunning)
                {
                    timer.StartTimer();
                }
                ToggleState(true, false);
                foreach (TargetHealth target in targets)
                {
                    if (!target.boss)
                    {
                        target.Revive();
                    }
                    else
                    {
                        boss = target;
                        boss.Kill();
                    }
                }
            }
            AudioSource.PlayClipAtPoint(activateSound, transform.position + Vector3.up);
        }
    }
Beispiel #7
0
    // 길 가다가 트리거링된 적을 바로 공격하도록 수정할 것
    TargetHealth FindTarget()
    {
        float minDistance = 999;
        int   minIndex    = -1;

        for (int i = 0; i < gController.targets.Length; i++)
        {
            // 지정된 타겟이 아니라면 공격하지 않음
            if (gController.targets [i].CompareTag(targetTag) == false)
            {
                continue;
            }

            TargetHealth targetHealth = gController.targets [i].GetComponent <TargetHealth> ();
            // 이미 타겟이 씬에서 제거되었거나, HP가 0 이하인 경우엔 넘어간다
            if (targetHealth == null || targetHealth.currentHealth <= 0)
            {
                continue;
            }
            float dist = Vector3.Distance(_currentTransform.position, (gController.targets [i] as GameObject).transform.position);
            if (minDistance >= dist)
            {
                minDistance = dist;
                minIndex    = i;
            }
        }

        if (minIndex > -1)
        {
            return(gController.targets [minIndex].GetComponent <TargetHealth> ());
        }
        else
        {
            return(null);
        }
    }
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray ray = cam.ViewportPointToRay(new Vector2(0.5f, 0.5f));
         if (Physics.Raycast(ray, out RaycastHit hit))
         {
             if (hit.transform.tag == "Enemy")
             {
                 TargetHealth target = hit.collider.gameObject.GetComponent <TargetHealth>();
                 if (target != null)
                 {
                     Debug.Log("Target hit for" + damageEnemy);
                     TargetHealth enemyHealthScript = hit.transform.GetComponent <TargetHealth>();
                     enemyHealthScript.Damage(damageEnemy);
                 }
             }
             else if (hit.transform.tag == "Exit")
             {
                 UnityEditor.EditorApplication.isPlaying = false;
             }
         }
     }
 }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        if (targetTag == null || targetTag == "")
        {
            return;
        }

        attackTimer += Time.deltaTime;

        // waypoint 따라 이동
        if (waypoints == null || waypoints.Length == 0)
        {
            return;
        }

        if (currentWaypointIndex > -1 && currentWaypointIndex < waypoints.Length)
        {
            if (CheckCurrentWaypointArrived())
            {
                currentWaypointIndex++;
            }
            else
            {
                if (currentWaypointIndex != previousWaypointIndex)
                {
                    nav.SetDestination(waypoints[currentWaypointIndex].transform.position);
                    previousWaypointIndex = currentWaypointIndex;
                }
            }
        }
        else
        {
            nav.enabled = false;
        }

        if (currentTarget == null)
        {
            currentTarget    = _myTargets [0].GetComponent <TargetHealth>();
            _isTargetInRange = false;
        }
        else
        {
            if (currentTarget.currentHealth <= 0)
            {
                currentTarget = null;
                RemoveTargetCandidate(_myTargets [0]);
                _isTargetInRange = false;
                return;
            }
            else
            {
                nav.SetDestination(currentTarget.transform.position);

                float distanceToTarget = Vector3.Distance(_currentTransform.position, currentTarget.transform.position);
                if (distanceToTarget > attackRange)
                {
                    _isTargetInRange = false;
                }
                else
                {
                    _isTargetInRange = true;
                }

                if (_isTargetInRange)
                {
                    if (attackTimer >= attackSpeed)
                    {
                        Attack();
                    }
                }
            }
        }



        return;


        TargetHealth newTarget = null;

        if (currentTarget == null || currentTarget.currentHealth <= 0)
        {
            newTarget = FindTarget();
            if (newTarget == null)
            {
                nav.enabled = false;
                Debug.Log("Game End");
            }
        }

        // 새로운 타겟을 찾았을 때, 해당 타겟이 현재 타겟과 다르다면 새로운 타겟을 현재 타겟으로 설정하고 초기화
        if (newTarget != null && newTarget != currentTarget)
        {
            currentTarget = newTarget;
            float distanceToTarget = Vector3.Distance(_currentTransform.position, currentTarget.transform.position);
            if (distanceToTarget > attackRange)
            {
                _isTargetInRange = false;
            }
            else
            {
                _isTargetInRange = true;
            }
        }

        if (currentTarget != null && currentTarget.currentHealth > 0)
        {
            if (_isTargetInRange)
            {
                if (attackTimer >= attackSpeed)
                {
                    Attack();
                }
            }
            else
            {
                nav.SetDestination(currentTarget.transform.position);

                float distanceToTarget = Vector3.Distance(_currentTransform.position, currentTarget.transform.position);
                if (distanceToTarget <= attackRange)
                {
                    _isTargetInRange = true;
                }
                else
                {
                    _isTargetInRange = false;
                }
            }
        }
        else
        {
            _isTargetInRange = false;
        }
    }
    void Start()
    {
        m_wordText          = GetComponent<Transform>().Find("ItemNameInput").GetComponent<Text>();
        m_clueText          = GetComponent<Transform>().Find("nameClue").GetComponent<Text>();
        m_toMenuButton      = GetComponent<Transform>().Find("ToMenu").gameObject;
        m_youWon            = GetComponent<Transform>().Find("YouWon").gameObject;
        m_youLost           = GetComponent<Transform>().Find("YouLost").gameObject;

        m_targetHealth      = GetComponent<Transform>().Find("TargetHealth").GetComponent<TargetHealth>();

        m_shotTouch         = GetComponent<Transform>().Find("shotTouch").gameObject;

        m_toMenuButton.SetActive(false);
        m_youWon.SetActive(false);
        m_youLost.SetActive(false);

        m_clueText.active   = false;
        m_timerKBUseHint    = 0;
        m_kbHintShowed      = false;

        registerToKeyboard();
        SceneManager.instance.registerForSceneEvent(new SceneManager.sceneEventHandler(sceneEvent));
    }