Пример #1
0
        private void Update()
        {
            if (Input.GetKey(KeyCode.Mouse0))
            {
                if (m_AllowNextShot)
                {
                    RaycastHit2D hit = Physics2D.Raycast(m_FirePoint.position, m_FirePoint.right, m_ShootRange);
                    Debug.DrawRay(m_FirePoint.position, m_FirePoint.right * m_ShootRange, Color.red, 2f);

                    if (hit)
                    {
                        PlayerControllerPrototype player = hit.collider.GetComponent <PlayerControllerPrototype>();

                        if (player)
                        {
                            if (hit.rigidbody)
                            {
                                hit.rigidbody.AddForce(-hit.normal * m_HitForce);
                            }
                        }
                    }

                    m_ShootTimer = ShootTimer(m_ShootDelay);
                    StartCoroutine(m_ShootTimer);
                }
            }
        }
Пример #2
0
        private void Start()
        {
            m_Camera = FindObjectOfType <Camera>();


            m_Rigidbody        = GetComponent <Rigidbody>();
            m_PlayerController = GetComponent <PlayerControllerPrototype>();
        }
Пример #3
0
        private void Shoot()
        {
            AudioManager.instance.Play("Hit");
            Debug.DrawRay(m_FirePoint.position, m_AimDirection.normalized * m_ShootRange, Color.red, m_ShootDelay);

            m_PlayerController.DisableMovement(m_RecoilStunTime); // Recoil
            m_Rigidbody.AddForce(-m_AimDirection * m_RecoilForce);

            RaycastHit hit;

            if (Physics.Raycast(m_FirePoint.position, m_AimDirection, out hit, m_ShootRange))
            {
                Debug.Log("kaas");

                PlayerControllerPrototype player = hit.transform.GetComponent <PlayerControllerPrototype>();
                if (player != null)
                {
                    player.TakeDamage(20);
                }



                // PlayerControllerPrototype player = hit.collider.GetComponent // Later IHitAble

                if (hit.collider.CompareTag("Player"))
                {
                    print("hoi");
                    hit.collider.gameObject.GetComponent <PlayerControllerPrototype>().TakeDamage(10); // Later IHitAble
                    print(hit.collider.gameObject + "HitObject");
                    if (hit.rigidbody)
                    {
                        player.DisableMovement(m_KnockbackStunTime);
                        hit.rigidbody.AddForce(-hit.normal * m_KnockbackForce); // Knockback
                    }
                }
            }
        }