Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        Ray        ray = new Ray(visionPoint.transform.position, visionPoint.transform.forward);
        RaycastHit hit;

        //Décommenter pour voir la vision des ennemis
        // laser.enabled = true;
        laser.SetPosition(0, ray.origin);

        if (Physics.Raycast(ray, out hit, visionRange, RaycastDetection))
        {
            laser.SetPosition(1, hit.point);
            if (hit.collider.tag == "Weapon")
            {
                WeaponPickupScript detectedWeapon = hit.collider.GetComponent <WeaponPickupScript>();
                if (myWeaponScript.currentWeaponType == null || myWeaponScript.currentWeaponType == "")
                {
                    myNavScript.ReachPoint(hit.point);
                    //Debug.Log("New Weapon Detected");
                }
                else
                {
                    if (detectedWeapon.weaponType == myWeaponScript.currentWeaponType && detectedWeapon.dmg > myWeaponScript.currentWeaponDmg)
                    {
                        myNavScript.ReachPoint(hit.point);
                        //Debug.Log("Better Weapon Detected");
                    }
                }
            }
            if (hit.collider.tag == "Player")
            {
                if (!(myWeaponScript.currentWeaponType == null) && !(myWeaponScript.currentWeaponType == ""))
                {
                    myNavScript.FollowPlayer(hit.collider.gameObject);
                    ESUI.Spotted(true);
                }
            }
        }
        else
        {
            laser.SetPosition(1, ray.GetPoint(visionRange));
        }

        visionPoint.transform.localEulerAngles = new Vector3(0, Mathf.PingPong(Time.time * visionSpeed, 70) - 35, 0);
    }
Beispiel #2
0
    void Update()
    {
        if (followingPlayer && player != null)
        {
            FollowPlayer(player);
        }
        if (followingPlayer && GetComponent <NavMeshAgent>().remainingDistance > visionRange)
        {
            followingPlayer = false;
            inMission       = false;
            player          = null;
            //Debug.Log("Player to follow is too far away");
            ESUI.Spotted(false);
        }

        if (GetComponent <NavMeshAgent>().remainingDistance < 0.3f && inMission && !followingPlayer)
        {
            inMission = false;
        }
        if (GetComponent <NavMeshAgent>().remainingDistance < 0.5f && !inMission)
        {
            GoToNextDestination();
        }
    }