- Home /
changing the target of camera through script
From a script attached to my trigger I want to change the smooth follow target of my main camera on trigger enter by an object. I have tried passing the main camera as a var to my trigger script then getting smooth follow and target through get component and setting it to a new target but it does not work.
Answer by qJake · Apr 12, 2010 at 04:44 AM
Just grab the component off the main Camera.
// C#
SmoothFollow sf = Camera.main.GetComponent(typeof(SmoothFollow)) as SmoothFollow;
sf.Target = myTransform;
Make sure that the SmoothFollow script has its class name as "SmoothFollow". I'm not sure exactly what the property is for the "Target", so I just called it "Target". Change this to whatever it should be.
Or, I$$anonymous$$HO slightly more elegant, using the generic version of GetComponent: SmoothFollow sf = Camera.main.GetComponent<SmoothFollow>();
@$$anonymous$$vanteTore: generics are not supported on Unity iPhone, so sometimes it's better to have example without them ;)
Your answer
Follow this Question
Related Questions
2.5d camera control script 1 Answer
Camera Toggle script 1 Answer
Camera look position is always fixed.. need help. 3 Answers
Make Arms Move Slow 0 Answers
Toggle between scripts with a script? 2 Answers