I have the following C# script that I am using to allow a player to enter and exit a vehicle, and fire the vehicle’s weapon whilst they are in the vehicle. However, I keep getting the following error code in the Console:
Assets/Scripts/Vehicle.cs(5,40): error CS0119: Expression denotes a ‘type’, where a ‘variable’, ‘value’ or ‘method group’ was expected.
using UnityEngine;
using System.Collections;
public class Vehicle : MonoBehaviour {
public float bulletSpeed = 10.0F;
public GameObject projectile = Rigidbody;
public float getInRange = 6.0F;
public Camera VehicleCamera;
public GameObject Player;
private bool InVehicle;
private bool VehicleControl;
public float Speed = 80.0F;
public float RotationSpeed = 100.0F;
public Transform _Player;
private float Distance;
public Transform _Vehicle;
private Vector3 VehiclePos;
void Start()
{
VehicleCamera.gameObject.SetActive(false);
}
void Update()
{
Distance = Vector3.Distance(_Player.position, transform.position);
if(Distance < 6)
{
if(Input.GetKeyDown(KeyCode.Tab))
{
InVehicle = true;
}
}
else if(InVehicle)
{
if(Input.GetKeyDown(KeyCode.Tab))
{
InVehicle = false;
VehiclePos = new Vector3(_Vehicle.transform.position.x + 5, _Vehicle.transform.position.y, _Vehicle.transform.position.z);
_Player.transform.position = VehiclePos;
}
}
if(InVehicle)
{
VehicleCamera.gameObject.SetActive(true);
Player.gameObject.SetActive(false);
VehicleControl = true;
if (Input.GetKeyDown(KeyCode.Return)) {
var clone = Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * bulletSpeed);
}
}
else
{
VehicleCamera.gameObject.SetActive(false);
Player.gameObject.SetActive(true);
VehicleControl = false;
}
if(VehicleControl)
{
float tr = Input.GetAxis("Vertical") * Speed;
float rot = Input.GetAxis("Horizontal") * RotationSpeed;
tr *= Time.deltaTime;
rot *= Time.deltaTime;
transform.Translate(0, 0, tr);
transform.Rotate(0, rot, 0);
}
}
void OnGUI()
{ if(InVehicle == false)
{
if(Distance < getInRange)
{
GUILayout.Label("Press TAB");
}
}
}
}