I was trying to make it so my player could bump into and knock over certain 3-D GameObjects. However, I have one error stating: “Assets/Scripts/Player_Controller.cs(58,39): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement”
Here’s my code-
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Player_Controller : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
// this script pushes all rigidbodies that the character touches
var pushPower = 2.0;
function OnControllerColliderHit (hit ControllerColliderHit)
{
var body = Rigidbody = hit.collider.attachedRigidbody;
}
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 10)
{
winText.text = "You Win!";
}
if (body == null || body.isKinematic) { return; }
if (hit.moveDirection.y & lt) -0.3; { return; }
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
body.velocity = pushDir * pushPower;
}
}