Created
January 13, 2017 01:55
-
-
Save naruse/f9c8ac90f236b53623593555d8e75e88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnityEngine; | |
using System.Collections; | |
public class ExampleClass : MonoBehaviour { | |
public Transform gunObj; | |
void Update() { | |
if (Input.GetMouseButton(0)) { | |
RaycastHit hit; | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
if (Physics.Raycast(ray, out hit)) { | |
Vector3 incomingVec = hit.point - gunObj.position; | |
Vector3 reflectVec = Vector3.Reflect(incomingVec, hit.normal); | |
Debug.DrawLine(gunObj.position, hit.point, Color.red); | |
Debug.DrawRay(hit.point, reflectVec, Color.green); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment