コード例 #1
0
 public void Hit(int damage)
 {
     myNavScript.FollowPlayer(player);
     currentHP -= damage;
     if (currentHP <= 0)
     {
         Instantiate(food, new Vector3(transform.position.x + 1, transform.position.y, transform.position.z), transform.rotation);
         Instantiate(food, new Vector3(transform.position.x - 0.7f, transform.position.y, transform.position.z + 0.7f), transform.rotation);
         Instantiate(food, new Vector3(transform.position.x - 0.7f, transform.position.y, transform.position.z - 0.7f), transform.rotation);
         gameObject.GetComponent <WeaponScript>().DropWeapon(true);
         Destroy(gameObject);
     }
     refreshUI();
 }
コード例 #2
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);
    }