Created
July 2, 2017 14:07
-
-
Save tsubaki/fb6b8f5adceaa9ce19b9aaf2534fda27 to your computer and use it in GitHub Desktop.
マウスの位置に向ける(Raycastなし)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Lookat2DByScreen : MonoBehaviour | |
{ | |
void Update () | |
{ | |
var pos = Camera.main.WorldToScreenPoint (transform.localPosition); | |
var rotation = Quaternion.LookRotation(Vector3.forward, Input.mousePosition - pos ); | |
transform.localRotation = rotation; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment