void Update()
    {
        if (Vector3.Distance(transform.position, player.position) < weapon.range)
        {
            weapon.Attack();
        }

        agent.destination = player.transform.position;

        ////slowly look at player
        //// look at the nearest cardinal direction
        //float heading = Quaternion.LookRotation(transform.forward).eulerAngles.y;
        //Vector3 lookAt = transform.position;
        //if (heading >= 0 + 45 && heading < 90 + 45) {
        //    // right
        //    lookAt.x += 1;
        //} else if (heading >= 90 + 45 && heading < 180 + 45) {
        //    // down
        //    lookAt.z -= 1;
        //} else if (heading >= 180 + 45 && heading < 270 + 45) {
        //    // left
        //    lookAt.x -= 1;
        //} else {
        //    // up
        //    lookAt.z += 1;
        //}

        //transform.LookAt(lookAt);

        //Quaternion lookQuat = Quaternion.LookRotation(player.position - transform.position);
        //transform.rotation = Quaternion.RotateTowards(transform.rotation, lookQuat, data.enemyRotSpeed * Time.deltaTime);
    }
Пример #2
0
 public void Attack()
 {
     if (Weapon == null)
     {
         Console.WriteLine("No item to attack!");
         return;
     }
     Weapon.Attack();
 }
    public override void Handle(string input)
    {
        // if game is paused
        if (Time.timeScale == 0)
        {
            // inspect
            if (input == "Fire2")
            {
                textContinueEventHandler.Invoke();
            }
            return;
        }

        // interact
        if (input == "Fire1")
        {
            Vector3 fwd = player.transform.TransformDirection(Vector3.forward);
            Vector3 pos = player.transform.position;
            pos.y = 1;
            RaycastHit hit;
            if (Physics.Raycast(pos, fwd, out hit, interactDistance))
            {
                print("Player wants to interact with " + hit.collider.name);
                playerInteractEventHandler.Invoke(hit.collider.gameObject);
            }
        }

        // inspect
        if (input == "Fire2")
        {
            Vector3 fwd = player.transform.TransformDirection(Vector3.forward);
            Vector3 pos = player.transform.position;
            pos.y = 1;
            RaycastHit hit;
            if (Physics.Raycast(pos, fwd, out hit, interactDistance))
            {
                print("Player wants to inspect " + hit.collider.name);
                playerInspectEventHandler.Invoke(hit.collider.gameObject);
            }
        }

        // attack
        if (input == "Fire3")
        {
            weapon.Attack();
        }

        if (input == "Jump")
        {
            playerMovement.Jump();
        }
    }