samedi 15 mai 2021

Random Teleport Character issue

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 and when my character comes into contact with a point he is able to teleport between the various points on the map randomly. As if it were a portal. Now 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 is already 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? Thank you.


public class Trasport : 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);


    }


}




Aucun commentaire:

Enregistrer un commentaire