- Home /
'transform' is not a member of 'Object' code problem
I'm currently trying to do a basketball game where the basketball instantiates at a certain position after the player presses the "shoot" key. The problem is I get this error message when compiling 'transform' is not a member of 'Object'
Here's the code:
var newball;
static var tempBasketBall: Rigidbody;
var pos: Transform[];
var ball1: Rigidbody;
var ball2: Rigidbody;
var ball3: Rigidbody;
var canControl1 = true;
var canControl2 = true;
var canControl3 = true;
var destroyTime: int = 6;
var player1: GameObject;
var player2: GameObject;
var player3: GameObject;
var b1Parent: Transform;
var b2Parent: Transform;
var b3Parent: Transform;
var yVelocity: float;
var zVelocity: float;
function Start ()
{
ball1 = Instantiate(tempBasketBall, pos[0].position, pos[0].rotation);
ball2 = Instantiate(tempBasketBall, pos[1].position, pos[1].rotation);
ball3 = Instantiate(tempBasketBall, pos[2].position, pos[2].rotation);
}
function Update ()
{
if(Input.GetButtonUp("Player1") &&canControl1)
{
ball1.useGravity = true;
ball1.velocity = transform.TransformDirection(0, yVelocity, zVelocity);
MakeBall1(pos[0]);
canControl1 = false;
}
}
function MakeBall1(pos)
{
yield new WaitForSeconds(1);
ball1 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation);
canControl1 = true;
}
The error points out to the instantiate section of the MakeBall1 function. How do I fix this? Help
Thanks in advance
Answer by PProductions · Sep 13, 2012 at 05:41 PM
var pos: Transform[];
ball1 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation);
These are your problems, pos is an array and this means you must give an index to use it's values. Also you don't need to use .transform as pos is already a transform. Here is an edited version, replace [i] with whatever index of the array you wish to use
ball1 = Instantiate(tempBasketBall, pos[i].position, pos[i].rotation);
Thank you for the response. I tried your suggestion, it seems to be giving me a new error message. It says "Type 'Object' does not support slicing". How do I fix this?
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613081014im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to get a shoot function working in unity using instantiate and it isn't working. 1 Answer
Instantiate Object at the extreme end of the object 0 Answers
How are you able to use a Transform argument for Instantiate? 2 Answers
Putting prefab into scene messes with the transform origin? 1 Answer
Instantiate Problem 2 Answers