hi as you can probably tell from the number of posts that i’ve done that i’m a complete noob. in 3d.
been doing 2d for a while but now im switching and trying to learn the c# language.
i’ve got this error:
Assets/Scripts/AIscript.cs(25,70): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
here is my code for 25- 70
can any one help me understand what i’m doing wrong?
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 2D coordinates, 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;
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()
{
tempVector = rigidbody.GetPointVelocity(transform.position) * Time.deltaTime * 1000;
rigidbody.AddForce (-tempVector.x, -tempVector.y, -tempVector.z);
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);
}
what is the code tag? i know what it does but whats the tag? \c? c?
Also i fooled around in unity for a while trying to figure out if there was a way to determine the exact line the error was on but i couldn’t find a way…
This is the specific problem it says its having
Assets/Scripts/AIscript.cs(25,69): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
// You shouldn't have to cast to GameObject here. (I'm assuming
// objCamera is of type GameObject.)
// Also, note that Camera.main always refers to the camera associated
// with the first game object (if any) that's tagged as 'MainCamera', so you
// could probably use Camera.main here instead.
objCamera = (GameObject) GameObject.FindWithTag ("MainCamera");
// You've used '=' where you want '==' (or CompareTag()). Also, you need
// to invoke .tag on an instance here. For example, if it were objCamera
// that you were interested in, you'd write 'if (objCamera.tag == "Player")'.
if (GameObject.tag = "Player") {thisIsPlayer == true;}
I’m trying to create a sort of collision script that will be used for both the players and the npc’s…
it reads that if the gameobject is the player (because it reads that it has the player tag) then this this and this, if it’s not the player then it must be an npc like a zombie or something and it does this this and this
I tried as you suggested and it gave me a:
Assets/Scripts/AIscript.cs(25,32): error CS0120: An object reference is required to access non-static member `UnityEngine.GameObject.tag’
should i try to make the player object a static object?