I’m working on a simple fps with another classmate. I was just wondering if anybody can help with the issues I’m having.
The camera is fixed as the game is on rails.
So far I have added the crosshair and connected it to the mouse.
I am coding in Javascript but my colleague is using c#.
He has created the code for the current behaviour of the raycast, which you see below.
using UnityEngine;
using System.Collections;
public class FPSInput : MonoBehaviour {
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0)){
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, 100)) {
Debug.DrawLine (ray.origin, hit.point);
if (hit.transform.tag == "Chicken")
{
print(hit.collider.tag);
Destroy(hit.rigidbody.gameObject,4.0f);
Vector3 explosionPos = transform.position;
hit.rigidbody.AddExplosionForce(5000, explosionPos, 25.0f, 1.0f);
}
}
}
}
}
What I’d like to know is the following:
Is it easy to add a projectile so that the viewer can actually see the bullet instead of the result of the bullet?
How can I add a score so that it increases by 10 everytime a chicken is shot?
Many thanks in advance. I’m a complete beginner to this, but I have completed the fps tutorial. However I just can’t seem to apply the knowledge to my game, and the switch from javascript to c# has confused me