- Home /
 
 
               Question by 
               tXxy · Nov 25, 2020 at 10:24 PM · 
                instantiatevariableclasspassing  
              
 
              Attach a value to an instantiate object and call it in the class of this object
Groundtile.cs script attachted to the plane
 bool SpawnMovingObstacle()
     {
         int spawnChance = Random.Range(1, 6);
 
         int spawnSide = Random.Range(5, 7);
         int rightSpawnIndex = 5;
         int leftSpawnIndex = 6;
 
         Transform rightSpawnPoint = transform.GetChild(rightSpawnIndex).transform;
         Transform leftSpawnPoint = transform.GetChild(leftSpawnIndex).transform;
 
         if (spawnChance == 1)
         {
             Instantiate(movingObstacle, rightSpawnPoint.position, Quaternion.identity, transform);
             return true;
         } 
         return false;
     }
 
               Here I am spawning a prefab which should move on the plane, I have two spawn points, one on the left the other on the right
collisionDetection.cs attached to the prefab object which gets instantiated:
 if (collision.gameObject.name == "Player")
         {
             //ask which spawn index do another if with constant force for each side
             //if (spawnSide == 5)
             //then move to the right
             
             //if (spawnSide == 6)
             //then move to the left
         }
 
               The idea is to attach the index number from the random.range to the spawned prefab so I can use the index number to view where the prefab spawned and depending on the site it will move to the other side
Sadly I don't know how to pass the number and passing a variable just finds a lot of other stuff on google
               Comment
              
 
               
              Your answer