Created
February 19, 2017 10:39
-
-
Save cadenburleson/35a3d4a5b577155eff057b68bc984b99 to your computer and use it in GitHub Desktop.
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 GunFollow: MonoBehaviour { | |
public GameObject objectToSpawn; | |
public Transform gun; | |
public Transform cam; | |
// Update is called once per frame | |
void Update () { | |
Ray ray = new Ray(cam.position, cam.forward); | |
RaycastHit hit; | |
if( Physics.Raycast( ray, out hit, Mathf.Infinity )) { | |
gun.LookAt (hit.point); | |
if (Input.GetButton("Fire1")) { | |
Instantiate( objectToSpawn, hit.point, Quaternion.LookRotation( hit.normal ) ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment