ReuseObject() public method

public ReuseObject ( GameObject prefab, Vector3 position, Quaternion rotation ) : void
prefab GameObject
position Vector3
rotation Quaternion
return void
    public void FireBullet(float angle)
    {
        /*
         * //Debug.Log("Fire");
         * //Vector3 eulers = lookRot.eulerAngles;
         * Quaternion rot = Quaternion.Euler(0, lookRot, 0);
         *
         * BulletController temp = Instantiate(tower.bulletPrefab, (Vector3)position + lookRot * firingHarness.transform.position, rot).GetComponent<BulletController>();
         * Rigidbody rigidbody = temp.GetComponent<Rigidbody>();
         * temp.damage = tower.damage;
         *
         * rigidbody.velocity = rot * (Vector2.up * 10);*/

        Quaternion rot = Quaternion.Euler(0, angle, 90);
        //BulletController temp = Instantiate(tower.bulletPrefab, firingHarnesses[currentFiringHarness++].transform.position, Quaternion.Euler(0, angle, 0)).GetComponentInChildren<BulletController>();
        GameObject       tempParent = PoolManager.ReuseObject(tower.bulletPrefab, firingHarnesses[currentFiringHarness++].transform.position, rot);
        BulletController temp       = tempParent.GetComponentInChildren <BulletController>();

        temp.parent = tempParent;
        Rigidbody tempRbody = temp.GetComponentInChildren <Rigidbody>();

        temp.rbody         = tempRbody;
        tempRbody.velocity = Quaternion.Euler(0, angle - 90, 0) * (Vector3.forward * tower.bulletVelocity);
        temp.tower         = this;

        currentFiringHarness = currentFiringHarness % firingHarnesses.Length;

        /*if (firingHarnesses.Length >= currentFiringHarness)
         *  currentFiringHarness = 0;*/

        if (tower.attackSpeed != 0f)
        {
            nextFireTime = Time.time + (1f / tower.attackSpeed);
        }
    }
示例#2
0
    private void Attack()
    {
        Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * 10f);
        float   angle = AngleBetweenPoints(mouseWorldPosition, transform.position);


        arrowPool.ReuseObject(transform.localPosition, Quaternion.Euler(-36f, 0f, angle));
        audioControl.PlayArrow();
        Invoke("ActivateShoot", WeaponCooldownTime);
    }
示例#3
0
 public void Spawn()
 {
     if (isPooled)
     {
         poolManager.ReuseObject(spawnType, transform.position, Quaternion.identity);
     }
     else
     {
         Instantiate(spawnType, transform.position, Quaternion.identity);
     }
     //GameObject obj = Instantiate(spawnType, transform.position, Quaternion.identity);
 }
示例#4
0
 private IEnumerator SpawnCoroutine()
 {
     isRunning = true;
     while (runForever || (spawnInstances - numPerSpawn) >= 0)
     {
         spawnInstances -= numPerSpawn;
         for (int i = 0; i < numPerSpawn; i++)
         {
             var obj = poolManager.ReuseObject(enemy, GetRandomPoint(minBounds, maxBounds), Quaternion.identity);
         }
         yield return(new WaitForSeconds(Random.Range(spawnMinDelay, spawnMaxDelay)));
     }
     isRunning = false;
 }
示例#5
0
    private void Start()
    {
        poolManager = FindObjectOfType <PoolManager>();
        //Debug.Log("Spawn");
        for (var i = 0; i < spawnObject.Length; i++)
        {
            PoolManager.instance.CreatePool(spawnObject[i], objectAmmount[i]);
            for (var j = 0; j < objectAmmount[i]; j++)
            {
                poolManager.ReuseObject(spawnObject[i], PointInArea(), Quaternion.identity);
                //spawnObject[i].transform.position = PointInArea();
                //spawnObject[i].SetActive(true);
            }

            //spawnObject[i].name = spawnObject[i].name;
            //spawnObject[i.transform.SetParent(GameObject.Find("ElementChase").transform.GetChild(0));
        }
    }
示例#6
0
    private void Update()
    {
        moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized;
        var     velocity     = moveInput * moveSpeed;
        Vector3 displacement = velocity * Time.deltaTime;

        Move(displacement);

        var isFirePressed = Input.GetButton("Jump");

        if (isFirePressed && canFire)
        {
            canFire = false;
            var bulletObj        = poolManager.ReuseObject(bullet, bulletSpawnPoint.position, Quaternion.identity);
            var bulletController = bulletObj.GetComponent <BulletController>();
            bulletController.speed      = bulletSpeed;
            bulletController.direction  = Vector2.up;
            bulletController.triggerTag = "Enemy";
            StartCoroutine(FireCoolDownRoutine());
        }
    }
示例#7
0
    public void SpanwAtVector(int id, Vector3 position_new)
    {
        PM.ReuseObject(StatusAnimationGO[id], position_new, Quaternion.identity);

        //Instantiate(StatusAnimationGO[id], position_new, Quaternion.identity);
    }
示例#8
0
    public void SpawnCastleObstacle()
    {
        GameObject obj = poolManager.ReuseObject(castleObstacles[Random.Range(0, castleObstacles.Length)], transform.position, Quaternion.identity);

        AdjustPos(obj);
    }
示例#9
0
 public void ReuseObject(GameObject prefab, Vector3 position, object args = null)
 {
     pool.ReuseObject(prefab, position, Quaternion.identity, args);
 }
示例#10
0
 public void FireArrow()
 {
     poolManager.ReuseObject(arrow, transform.position, Quaternion.identity);
 }
示例#11
0
 public void Reuse()
 {
     poolManager.ReuseObject(prefab, GetSpawnPosition(), UnityEngine.Random.rotation);
 }
示例#12
0
    public void SpawnVillagePlatform(Vector2 r)
    {
        GameObject obj = poolManager.ReuseObject(spawnVillagePlatform[Random.Range(0, spawnVillagePlatform.Length)], new Vector3(r.x, r.y, 0f), Quaternion.identity);

        AdjustPos(obj);
    }