示例#1
0
    public void SpawnKidShooting()
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePos.z = 0;

        GameObject bullet = Instantiate(mngScript.bulletsPrefabs[kidWeaponIndex],
                                        mngScript.bulletsSpawns[kidWeaponIndex].position,
                                        mngScript.bulletsSpawns[kidWeaponIndex].rotation) as GameObject;

        bullet.transform.parent     = mngScript.bulletsSpawns[kidWeaponIndex].transform.parent;
        bullet.transform.localScale = mngScript.bulletsSpawns[kidWeaponIndex].transform.localScale;
        bullet.transform.position   = mngScript.bulletsSpawns[kidWeaponIndex].position;
        Vector3 direction = mousePos - bullet.transform.position;
        float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        /*
         * if(angle < 100){
         *      angle = 100;
         * }
         * if(angle > 200){
         *      Debug.Log("habal");
         *      angle = 200;
         * }
         */
        BulletMover bmScript = bullet.GetComponent <BulletMover>();

        bmScript.SetDestination(mousePos);

        bullet.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        SoundManager.PlaySFX("Kid_Shoot");
    }
 public static void ReturnObject(BulletMover obj)
 {
     obj.gameObject.SetActive(false);
     obj.transform.SetParent(Instance.transform);
     Instance.poolingObjectQueue.Enqueue(obj);
     obj.gameObject.transform.position = new Vector2(100, 0);
 }
示例#3
0
        protected void MoveBullet(GameObject bulletPrefab)
        {
            BulletMover bulletMover = bulletPrefab.GetComponent <BulletMover>();

            if (bulletMover != null)
            {
                bulletMover.MoveForward();
            }
        }
示例#4
0
        void BounceBullet(BulletMover bulletMover, Vector3 surfaceNormal, float surfaceBounceFactor)
        {
            if (Vector3.Angle(bulletMover.transform.forward, surfaceNormal) < 90f)
            {
                return;
            }

            var reflectionVector     = ReflectIncomingVector(bulletMover.transform.forward * bulletMover.Speed, surfaceNormal);
            var scaledOutgoingVector = ScaleVectorInNormalDirection(reflectionVector, surfaceNormal, surfaceBounceFactor);

            bulletMover.transform.LookAt(bulletMover.transform.position + scaledOutgoingVector);
            bulletMover.Speed = scaledOutgoingVector.magnitude;
            bulletMover.transform.Translate(Vector3.forward * bulletMover.Speed * Time.deltaTime);
        }
示例#5
0
    private void FireNormal(int weap, int weapLevel)
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePos.z = 0;
        GameObject bullet = Instantiate(mngScript.bulletsPrefabs[weap],
                                        mngScript.bulletsSpawns[weap].position,
                                        mngScript.bulletsSpawns[weap].rotation) as GameObject;

        bullet.transform.parent     = mngScript.bulletsSpawns[weap].transform.parent;
        bullet.transform.localScale = mngScript.bulletsSpawns[weap].transform.localScale;
        bullet.transform.position   = mngScript.bulletsSpawns[weap].position;
        bullet.transform.parent     = null;
        Vector3 direction = mousePos - bullet.transform.position;
        float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        if (angle > 80)
        {
            angle = 80;
        }

        //if(angle < 0){
        //    angle = 0;
        //}

        BulletMover bmScript = bullet.GetComponent <BulletMover> ();

        bmScript.damage = DataHelper.WeaponsPowerPerUpgrade[weap, weapLevel];

        //new for modificatoins
        if (weap == 0 || weap == 1) //pistol or gun
        {
            bmScript.SetDestination(mousePos);
        }


        bullet.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }
示例#6
0
    private void FireBows(int weap, int weapLevel)
    {
        GameObject [] bulletsList = new GameObject[DataHelper.WeaponsFiresPerUpgrade[weap, weapLevel]];

        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePos.z = 0;

        for (int i = 0; i < bulletsList.Length; i++)
        {
            GameObject bullet = Instantiate(mngScript.bulletsPrefabs[weap],
                                            mngScript.bulletsSpawns[weap].position,
                                            mngScript.bulletsSpawns[weap].rotation) as GameObject;
            bullet.transform.parent     = mngScript.bulletsSpawns[weap].transform.parent;
            bullet.transform.localScale = mngScript.bulletsSpawns[weap].transform.localScale;
            bullet.transform.position   = mngScript.bulletsSpawns[weap].position;
            bullet.transform.parent     = null;


            BulletMover bmScript = bullet.GetComponent <BulletMover> ();
            bmScript.damage = DataHelper.WeaponsPowerPerUpgrade[weap, weapLevel];

            //new for modificatoins
            //bmScript.SetDestination(mousePos);

            bulletsList[i] = bullet;
        }

        Vector3 direction = mousePos - bulletsList[0].transform.position;
        float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        if (angle > 80)
        {
            angle = 80;
        }
        //if(angle < 0){
        //    angle = 0;
        //}
        //bulletsList[0].transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

        for (int i = 0; i < bulletsList.Length; i++)
        {
            if (i == 0)
            {
                bulletsList[i].transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
                bulletsList[0].GetComponent <BulletMover>().SetDestination(mousePos);
            }
            else if (i == 1)
            {
                bulletsList[i].transform.rotation = Quaternion.AngleAxis(angle - 10, Vector3.forward);
                bulletsList[0].GetComponent <BulletMover>().brothers.Add(bulletsList[i].transform);
            }
            else if (i == 2)
            {
                bulletsList[i].transform.rotation = Quaternion.AngleAxis(angle + 10, Vector3.forward);
                bulletsList[0].GetComponent <BulletMover>().brothers.Add(bulletsList[i].transform);
            }
            else if (i == 3)
            {
                bulletsList[i].transform.rotation = Quaternion.AngleAxis(angle - 20, Vector3.forward);
                bulletsList[0].GetComponent <BulletMover>().brothers.Add(bulletsList[i].transform);
            }
            else if (i == 4)
            {
                bulletsList[i].transform.rotation = Quaternion.AngleAxis(angle + 20, Vector3.forward);
                bulletsList[0].GetComponent <BulletMover>().brothers.Add(bulletsList[i].transform);
            }


            //bulletsList[i].transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        }
    }
示例#7
0
 private BulletMover()
 {
     bulletMover = this;
 }