Hi there!
I am making a top-down shooter, using the EVAC-CITY tutorial i found at the rebelplanet creations website. I am doing the programming, but whenever i try to run the game, i get the following errors:
Assets/Scripts/AIscript.cs(21,16): error CS0120: UnityEngine.GameObject.tag': An object reference is required for the nonstatic field, method or property** **Assets/Scripts/AIscript.cs(21,16): error CS0120: UnityEngine.GameObject.tag’: An object reference is required for the nonstatic field, method or property
Assets/Scripts/AIscript.cs(50,1): error CS0246: The type or namespace name on' could not be found. Are you missing a using directive or an assembly reference?** **Assets/Scripts/AIscript.cs(61,11): error CS0120: UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)': An object reference is required for the nonstatic field, method or property
Assets/Scripts/AIscript.cs(61,11): error CS0120: `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)': An object reference is required for the nonstatic field, method or property
I am reasonably new to C# programming, so i do not know what is wrong. Here is the script:
using UnityEngine;
using System.Collections;
public class AIscript : MonoBehaviour {
//game objects (variables which point to game objects)
private GameObject objPlayer;
private GameObject objCamera;
//input variables (variables used to process and handle input)
private Vector3 inputRotation;
private Vector3 inputMovement;
//identity variables (variables specific to the game object)
public float moveSpeed = 100f;
private bool thisIsPlayer;
// calculation variables (variables used for calculation)
private Vector3 tempVector;
private Vector3 tempVector2;
// Use this for initialization
void Start () {
objPlayer = (GameObject) GameObject.FindWithTag ("Player");
objCamera = (GameObject) GameObject.FindWithTag ("MainCamera");
if (GameObject.tag == "Player") { thisIsPlayer = true; }
}
// Update is called once per frame
void Update () {
FindInput();
ProcessMovement();
if (thisIsPlayer == true)
{
HandleCamera();
}
}
void FindInput ()
{
if (thisIsPlayer == true)
{
FindPlayerInput();
} else {
FindAIinput();
}
}
void FindPlayerInput ()
{
// find vector to move
inputMovement = new Vector3( Input.GetAxis("Horizontal"),
0,Input.GetAxis("Vertical") );
// find vector to the mouse
tempVector2 = new Vector3(Screen.width * 0.5f,0,Screen.height *
0.5f); // the position of the middle of the screen
tempVector = Input.mousePosition; // find the position of the moue
on Screen ;
tempVector.z = tempVector.y; // input mouse position gives us 2Dcoordinates, I am moving the Y coordinate to the Z coorindate in temp Vector and setting the Y coordinate to 0, so that the Vector will read the Input along the X (left and right of Screen) and Z (up and down Screen) axis, and not the X and Y (in and out of Screen) axis
tempVector.y = 0;
Debug.Log(tempVector);
inputRotation = tempVector - tempVector2; // the direction we want face/aim/shoot is from the middle of the Screen to where the mouse is pointing
}
void FindAIinput ()
{
}
void ProcessMovement()
{
Rigidbody.AddForce (inputMovement.normalized * moveSpeed * Time.deltaTime);
transform.rotation = Quaternion.LookRotation(inputRotation);
transform.eulerAngles = new Vector3(0,transform.eulerAngles.y + 180,0);
transform.position = new Vector3(transform.position.x,0,transform.position.z);
}
void HandleCamera()
{
objCamera.transform.position = new Vector3(transform.position.x,
15,transform.position.z);
objCamera.transform.eulerAngles = new Vector3(90,0,0);
}
}
Please can you help me, i do not know what to do ![]()
Thanks in advance,
Michael Brockwell