Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created July 2, 2017 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/fb6b8f5adceaa9ce19b9aaf2534fda27 to your computer and use it in GitHub Desktop.
Save tsubaki/fb6b8f5adceaa9ce19b9aaf2534fda27 to your computer and use it in GitHub Desktop.
マウスの位置に向ける(Raycastなし)
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