100 Days of VR: Day 9 Setting up a Weapon

Adding our Weapon

Creating our weapon

Adding the Shooting Script

using UnityEngine;public class PlayerShootingController : MonoBehaviour
{
public float Range = 100;
private Camera _camera;
private ParticleSystem _particle;
void Start () {
_camera = Camera.main;
_particle = GetComponentInChildren<ParticleSystem>();
}

void Update () {

if (Input.GetMouseButton(0))
{
Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, Range))
{
print("hit " + hit.collider.gameObject);
_particle.Play();
}
}
}
}

End of Day 8

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store