- Home /
Question by
SebastianBolinger · Jan 03, 2012 at 11:16 AM ·
cameraplayerobjectsmultiple
Multiple player objects with using one camera
I'm not the best programmer so I've been searching through forums but I can't seem to find my answer where I've got a game where there are multiple objects that the player control but I'm having trouble creating a script in java that lets the player switch though the objects with one camera simply pressing the 1-5 keys. Is there any example scripts or resource that I can use so I can head in the right direction?
Comment
Answer by Owen-Reynolds · Jan 03, 2012 at 05:06 PM
Most camera scripts have a target
variable, which they track. Dragging in a new target switches who you follow. Dragging it over "in code" will also switch:
// in Update (which is where you read Keys):
if(Input.GetKeyDown("2")) {
target = GameObject.Find("player2");
//followDist=40; // if followDist exists in the script
}
I just made up followDist
, as an example of how you could also tweak the positioning variables when you switch.