- Home /
Issue's With Positioning
So I have been playing with this a ton, and the issue I'm running into is the variables I am using. They don't really like one another when I try to get my random objects position. But I am not to sure on how to "re word" or solve this issue. I've tried a few different things but they all have a conflict with one another.
Here's my public variables
     public GameObject[] numbers;
     public GameObject ball;
     public GameObject pickedNumber; //The random number picked
     public int index;
     public Transform target;
     public float speed;
Now here's the for loop trying to grab the position of pickedNumber and move the ball to that position.
 void Update () {
         //float waitTime = 8;
         float step = speed * Time.deltaTime * 2;
         
         //yield return new WaitForSeconds (waitTime);
         
         for (int i = 0; i <= 19; i++) {
             //Finding Game Objects
             numbers = GameObject.FindGameObjectsWithTag ("num");
             ball = GameObject.FindGameObjectWithTag ("ball");
             
             //Picking the random cube
             index = Random.Range (0, numbers.Length);
             pickedNumber = numbers [index];
             
             print ("number picked");
             print (pickedNumber.name);
             
             print ("numer postion");
             print (pickedNumber.transform.position);
 
             //Setting up position
             transform.position = new Vector3 (0, 0, 0);
 
             //Moving ball to cube
             Transform numPos;
             numPos = pickedNumber;
             target = numPos;
             ball.transform.position = Vector3.MoveTowards(transform.position, target.position, step);
             
             //Checking balls position 
             print ("ball");
             print (ball.transform.position);
             
             //Pause here
             print ("PAUSE!");
             //yield return new WaitForSeconds (waitTime);
             
             //Ball Returns to position
             ball.transform.position = new Vector3 (0, 0, 0);
             print ("ball reset");
             print (ball.transform.position);
         }
     }
The issue seems to be that pickedNumber can't be changed from a Unity.Gameobject to a Unity.Transform.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                