Esempio n. 1
0
    private void Update()
    {
        float   X      = Input.GetAxis("Horizontal");
        float   Z      = Input.GetAxis("Vertical");
        Vector3 Moving = transform.right * X + transform.forward * Z;

        controller.Move(Moving * SPD * Time.deltaTime);
        velocity.y += Gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
        Grounded = Physics.CheckSphere(GroundCheck.position, groundDis, ground);
        if (Grounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }
        if (Input.GetButtonDown("Jump") && Grounded)
        {
            velocity.y = Mathf.Sqrt(Jump * -2f * Gravity);
        }

        //Shlash
        if (Input.GetButtonDown("Fire1"))
        {
            Slashing();
        }
        void Slashing()
        {
            RaycastHit slash;

            if (Physics.Raycast(cam.transform.position, cam.transform.forward, out slash, range))
            {
                Debug.Log(slash.transform.name);


                EnemyHealth EnemyHp = slash.transform.GetComponent <EnemyHealth>();
                if (EnemyHp != null)
                {
                    EnemyHp.DamageToHealth(Damage);
                }
            }
        }
    }