- Home /
Question by
UltraConstructor · Feb 25, 2021 at 06:27 PM ·
2drotationrotate object
2d - How do i make an object spawn facing the center of the screen?
I'd like an enemy, when generated, to immediately face the center of the screen.
Comment
Answer by Ermiq · Feb 26, 2021 at 05:45 AM
public class Enemy : MonoBehaviour
{
// in the inspector drag your camera on this field
public Camera cam;
void Start()
{
Vector3 screenCenterPointInWorld =
cam.ScreenToWorldPoint(Screen.width * 0.5f, Screen.height * 0.5f, 0);
transform.LookAt(screenCenterInWorld);
}
}