Hello,
I create a game with planets and a player.
On the first hand I have into planets:
- Custom Class GravityPlanetAttractor and a scipt swithPlayerPlanet.
public class GravityPlanetAttractor : MonoBehaviour
{
...;
}
And on the other hand my Player with:
- A script witch control mouvement and rotation and a script for attract a rotate this around the current planet
public class GravityBodyScript : MonoBehaviour
{
//objet attractif
public GravityPlanetAttractor planet;
...;
}
I would like to change the instance of a planet when the player enter in a new planet.
For that I have a scipt witch use a instance of GravityPlanetAttractor per planets.
I would like, with the next script, change the reference of the GravityPlanetAttractor to the new planet witch the player is enter.
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
GravityPlanetAttractor planet = transform;
gameObject.GetComponent<GravityBodyScript>().planet = planet;
}
}
but obviously unity don’t create a method to change a transform object into a GravityPlanetAttractor, so I don’t know how to do this.
Can any one (understand me and ) help me ?
thanks for reading and for answers.