private void createProjectile(Animator animator)
    {
        if (getEquipedWeapon(animator) != null && getEquipedWeapon(animator).isProjectileWeapon)
        {
            GameObject projSample = getEquipedWeapon(animator).Projectile; // get the projectile to create

            /* **IF YOU ARE NOT USING THE MOUSE USE THIS** */
            Vector3 dir = new Vector3(animator.GetFloat("lastHorizontal"), animator.GetFloat("lastVertical"), 0); // get the direction to send the projectile into if you are not using the mouse

            GameObject proj = Instantiate <GameObject>(projSample) as GameObject;                                 // create a new instance of the projectile (A copy/new bullet)
            proj.transform.position = animator.gameObject.transform.position;                                     // set the origin position to the player's position
            proj.SetActive(true);

            MoveProjectile moveProjectile = proj.GetComponent <MoveProjectile>(); // get ready to setup the movement behaviour

            /*  **IF YOU ARE USING THE MOUSE USE THIS**
             * Vector3 screenPos = Camera.main.WorldToScreenPoint(animator.gameObject.transform.position); // take into account the camera space if you are using the mouse
             * dir = (Input.mousePosition - screenPos).normalized;
             */

            if (dir == new Vector3(0, 0, 0))
            {
                dir = new Vector3(0, -1, 0); // default to shooting down
            }
            moveProjectile.MoveDir = dir;
            moveProjectile.Shooter = animator.gameObject;
        }
    }
Example #2
0
 void Shoot()
 {
     GunSound.Play();
     MoveProjectile curr_Bullet = Instantiate(bullet, MuzzlePoint.position, MuzzlePoint.rotation);
 }