- Home /
Spawned an object but it faces the wrong way. What's the fix?
public void Spawn()
{
GameObject monster=(GameObject)Instantiate(spawnPrefab, transform.position, Quaternion.identity);
monster.name="Monster";
}
That's my code. Like I said, it's facing the wrong way. I'm going to be spawning this prefab object several times throughout my game. Is there a way to set it so that it automatically rotates itself to face my first person camera when it spawns? Answers in CSharp please, it's the language I need to use for this project. I've had a look at this but to be honest with you I don't really understand it. I think it's along the right lines though. Thank you!
Answer by Sundar · Dec 06, 2013 at 05:49 PM
Try this
public void Spawn()
{
GameObject monster=(GameObject)Instantiate(spawnPrefab, transform.position, Quaternion.identity);
monster.transform.LookAt( Camera.main.transform );
monster.name="Monster";
}
Answer by Spinnernicholas · Dec 06, 2013 at 05:31 PM
After you spawn it, you can call Transform.LookAt to make it rotate towards the camera.
Your answer
Follow this Question
Related Questions
Can the Camera Smoothly rotate AFTER a button is pressed? (Javascript) 1 Answer
camera move x axis 2 Answers
Set camera angle in a script using the same system as the properties page?? 0 Answers
Help getting the target and camera rotation to match 0 Answers
Turning character with transform.Rotate 0 Answers