- Home /
Question by
unluckyboi112 · Jan 20 at 02:29 AM ·
ask
Please help, why? Input.mouse.mouseposition is doesn't work in side the game window but works outside?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Rotatate : MonoBehaviour {
void Update()
{
Vector3 gunpos = Camera.main.ScreenToViewportPoint(Input.mousePosition);
if (gunpos.x < transform.position.x)
{
transform.eulerAngles = new Vector3(transform.rotation.x, 180f, transform.rotation.y);
}
else
{
transform.eulerAngles = new Vector3(transform.rotation.x, 0f,transform.rotation.z);
}
}
}
Comment
Answer by unluckyboi112 · Jan 20 at 02:30 AM
Video : https://www.reddit.com/r/Unity2D/comments/s87qi4/please_help_why_inputmousemouseposition_is_doesnt/
Answer by arrowmaster1252 · Jan 20 at 02:37 AM
I'm no expert, but I think you should be using screen to world point.