0

So, I have a Scriptable Object(SO) as databases that contain many data and one of them is the Vector3 of the object in the new scene. I want to jump from scene 0 to scene 1 with Vector3 data from SO as the spawn point. Here's an example of the code.

'''

public Transform target; 
public Vector3 loc; //This is just a dummy, I'll retrieve data from SO later.

void Start()
{
    target = GameObject.FindWithTag("Player").transform;
    target.transform.position = Vector3(loc); //Here is the problem. 
}

'''

I can store data as x, y, z then pass it to new Vector3, but I think that will be inefficient. Any idea? I've been searching through the internet and nothing satisfied me.

1 Answers1

0

Oh now I see. For valid c# it would at least be

target.transform.position = new Vector3(loc.x, loc.y, loc.z);

but actually it is simply

target.transform.position = loc;

Vector3 is a struct so you don't need to use new nor a constructor at all since it is anyway assigned by value not by reference

derHugo
  • 83,094
  • 9
  • 75
  • 115
  • Oh yess.. this is. I don't know how to write the code simply cause I'm a newbie (like I just learn it a few weeks ago). Earlier, I can't pass it directly cause I don't know the way or I get a bug. Thank you, man! – Novia Rahmayanti Feb 07 '21 at 23:24