Esempio n. 1
0
    private BulletInstance InstantiateBullet(Bullet prefab, bool active)
    {
        Bullet bullet = Instantiate <Bullet>(prefab, _bulletPoolWrapper.transform);

        bullet.gameObject.SetActive(active);
        BulletInstance instance = new BulletInstance
        {
            active   = active,
            instance = bullet
        };

        return(instance);
    }
Esempio n. 2
0
    public Bullet SpawnBullet(Bullet prefab, Vector2 position, Vector2 direction, float charge, GameObject owner, bool superCharged)
    {
        PreAllocateBullets(prefab);
        BulletInstance availableBullet = FindAvailableBulletInstance(prefab);

        availableBullet.active = true;

        Bullet bullet = availableBullet.instance;

        bullet.gameObject.SetActive(true);
        bullet.transform.position = new Vector3(position.x, position.y, 0.0f);
        bullet.Initialize(charge, direction, owner, superCharged);

        return(bullet);
    }
Esempio n. 3
0
    private BulletInstance FindAvailableBulletInstance(Bullet prefab)
    {
        List <BulletInstance> bulletInstances = _bulletList[prefab];

        for (int i = 0; i < bulletInstances.Count; i++)
        {
            BulletInstance bulletInstance = bulletInstances[i];
            if (!bulletInstance.active)
            {
                return(bulletInstance);
            }
        }

        BulletInstance newInstance = InstantiateBullet(prefab, true);

        bulletInstances.Add(newInstance);

        return(newInstance);
    }
Esempio n. 4
0
    private void Shoot()
    {
        transform.Rotate(0f, Input.GetAxis("Mouse X") * sensetive, 0f);
        animHero.SetTrigger("Shoot");

        if (Input.GetMouseButton(0) & shootTime <= 0)
        {
            Rigidbody BulletInstance;
            BulletInstance = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as Rigidbody;
            BulletInstance.AddForce(spawnPoint.forward * shootForce);

            shootTime = speedShot;
        }

        if (shootTime > 0)
        {
            shootTime -= Time.deltaTime;
        }
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        float moveH = Input.GetAxis("Horizontal");
        float moveV = Input.GetAxis("Vertical");

        if (Input.GetKey(KeyCode.UpArrow))
        {
            Vector3 PosisiPlayer = transform.position;
            PosisiPlayer.z    += 0.01f;
            transform.position = PosisiPlayer;
            movex = Input.GetAxis("Horizontal");
            Anim.SetFloat("movex", movex);
            movey = Input.GetAxis("Vertical");
            Anim.SetFloat("movey", movey);
            transform.Translate(movespeed * moveH * Time.deltaTime, 0f, movespeed * moveV * Time.deltaTime);
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            Vector3 PosisiPlayer = transform.position;
            PosisiPlayer.z    -= 0.01f;
            transform.position = PosisiPlayer;
            movex = Input.GetAxis("Horizontal");
            Anim.SetFloat("movex", movex);
            movey = Input.GetAxis("Vertical");
            Anim.SetFloat("movey", movey);
            transform.Translate(movespeed * moveH * Time.deltaTime, 0f, movespeed * moveV * Time.deltaTime);
        }
        Rigidbody BulletInstance;

        if (Input.GetButtonDown("Fire1"))
        {
            BulletInstance = Instantiate(test, target.position, target.rotation) as Rigidbody;
            BulletInstance.AddForce(target.forward * 2000);
        }
        else if (Input.GetButtonDown("Fire2"))
        {
            BulletInstance = Instantiate(test2, target.position, target.rotation) as Rigidbody;
            BulletInstance.AddForce(target.forward * 1300);
        }
    }