So think of a scene with portals and each portal has a connected portal so when you enter it, you always go to the other one and vise-versa. Now my question is, is there a way to show this in the Editor. When I’m creating my scenes can I have a visual representation in the editor of which portal would be connected to which via a line connection or something?
Maybe create a protal with a list then keep track in some other script how many other protals have been spawned and keep adding the portals that now get spawned (assuming there can be more than 2 but only two connected) and if said number (in my exsample 2) had been reached set it back to zero and say the first portal to get the direction to the second and drawing a ray in that direction with the distance
The first Portal
public List<Transform> Portals;
void Start()
{
//Add this Portal
Portals.Add(this.transform);
}
void Update()
{
//Checking if enough Portals exist to not freak the computer out
if(Portals.Count <= 2)
{
Vector 3 dir = transform.positon - Portals[1].position;
float dist = Vector3.Distance(transform.position, Portals[1].position);
//Draw Ray from Position in direction with distance
Debug.DrawRay(transform.position, dir * dist);
}
}
The “PotalHandler”
public int totalPortalsSpanwned = 0;
pu
public Portal firstPotal;
//Adress how many Portals should be made at maximum and add first Portal
void AddPotal(int maxNumberOfPortals, Portal portal)
{
if(totalPortalsSpanwned != maxNumberOfPortals)
{
if(ttotalPortalsSpanwned == 0)
{
firstPortal = portal;
}
totalPortalsSpanwned++;
}else{
firstPortal.Portals.Add(portal);
//Reset to normal to make next two portals
firstPortal = null;
totalPortalsSpanwned = 0;
}
}
So this is good and it will work but how can I get this to run when the game isn’t. When I’m building out my level I wanted to see the rays while the game isn’t running.
Ah so the player can’t create portals they are already there? Because then all you need to do is place the portals and assign the second portal to the List of the first one and add [ExecuteInEditMode] at the top of the portal script
For drawing lines in the editor at design time you might want to take a look at Gizmos.DrawLine and Handles.DrawLine
Yes! Thank you very much. I’m just using portals as an example. I’m prototyping a roguelike with this 3d world but to make the game less flat there are stairs and inclines but for now the player is just going to teleport up stairs because for the terms of the prototype I am far too lazy to have it look good and work for now and I just wanted to see the connections so I don’t get messed up while scene building.
Otherwise you can use void OnDrawGizmosSelected I think too just put it in there if [ExecuteInEditMode] freaks you computer to much out