Hello all,
I have the following script which successfuly spawns an FPS camera when the assigned button is pressed. What I would like to know is how to spawn the camera at the current location rather than the location of the game object. The plan is to be able to switch between an FPS walker and an FPS flyer (if that makes sense?). Presumably I have to change the transform.position and transform.rotation but I’m not sure what to. Any ideas?
Thanks in advance.
Code:
var camfpsPrefab : GameObject;
function Update () {
if (Input.GetButtonDown (“Fire1”)){
Instantiate (camfpsPrefab, transform.position, transform.rotation);
}
}
Hmm not sure if this is exactly what your looking for but check this site out http://marraboy.blogspot.com/2009/01/changing-camera-views.html
That looks like it might be useful but I’m still unsure which part of that would reference the current location. My scripting skills are VERY basic indeed. Also would I be right in thinking the script in the link is in C#. What little scripting I know is in Javascript.
Cheers
The easiest way to go is probably to have a camera on both objects and just disable the one you don’t need (use the enabled property to enable/disable cameras).
Agreed, this is how I solved this problem, unity will automatically swap between as many cameras as you want as long as the camera.enabled is set to true on the one you want to be looking through.
Oh and javascript vs c# scripts - it might be bad practice, but they sit happily to next to each, I use both 