Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* I'm making an object pool for bullets in my game. I had it working fine in JS, but I needed to convert this project * to C#. Now I receive the error: "Type 'object' does not contain a definition for 'gameObject' and no extension
- * method 'gameObject' of type 'object' could be found"
- * It's referring to this line:
- * newBullet.gameObject.transform.position = myTransform.position;
- *
- * This line: var newBullet = gameManager.GetComponent<GameManager>().enemyBulletStack.Pop();
- * returns an object (a bullet). How do I return a game object?
- *
- public IEnumerator Shoot(float delay) // waits for 'delay' seconds, then shoots directly at the player
- {
- yield return new WaitForSeconds(delay);
- // get a bullet from the stack
- var newBullet = gameManager.GetComponent<GameManager>().enemyBulletStack.Pop();
- // position and enable it
- newBullet.gameObject.transform.position = myTransform.position;
- newBullet.gameObject.active = true;
- // calculate the direction to the player
- var shootVector = gameManager.GetComponent<GameManager>().player.transform.position - myTransform.position;
- // normalize this vector (make it length 1)
- shootVector.Normalize();
- // scale it up to the correct speed
- shootVector *= enemyBulletSpeed;
- newBullet.motion = shootVector;
- }
RAW Paste Data