I'm starting to take my first steps on unity and I'm trying to make a simple 2d game. I would like to create a teleport within the map. When my character comes into contact with a point he would be able to teleport between the various points on the map randomly as if it were a portal.
I have managed to insert a list with the points where it can move and with the Random function, I can move it. The problem is that the random function also calls the point where my character already is and therefore does not move.
This is what I would like to do: If I have three points A B C my character enters point A and can move to points B and C. If he goes to point B he can move to A and C and so on.
Now my character if he enters point A moves randomly to A B C.
How can I go about fixing it?
public class Transport : MonoBehaviour
{
public List<GameObject> Portal = new List<GameObject>();
public GameObject Player;
public void changePortal()
{
int aCaso = Random.Range(0, Portal.Count);
Player.transform.position = new Vector2(Portal[aCaso].transform.position.x, Portal[aCaso].transform.position.y);
}
}
this is the piece there code where the error appears
public prova ipa = null;
void Teleport()
{
if ((CATTURA.phase == InputActionPhase.Performed) && (contatto == true))
{
if (ipa != null)
{
ipa.changePortal(); ***this is the code for teleporting
*** error CS7036: There is no argument given that corresponds
to the required formal parameter 'sourcePortal' of
'prova.changePortal(GameObject)’***
}
}
}