- Home /
Why can't unity see my variable declaration?
Hi, I have tried to remove this problem multiple times without success. Error message:
Assets/Scripts/PlayerController.cs(45,46): error CS1525: Unexpected symbol `movement'
Here's the script:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 1000.0F;
public float gravity = 1.0F;
public float fallSpeed = 2.0F;
public float moveforward;
public float slowdown;
private bool jumping;
private float v;
private float h;
private Rigidbody rb;
private Transform transform;
private Vector3 movement;
void Start ()
{
rb = GetComponent<Rigidbody> ();
}
void Update ()
{
h = Input.GetAxis ("Horizontal");
jumping = Input.GetButtonDown ("Jump");
h *= speed;
movement = Vector3 (h, 0.0f, moveforward);
rb.AddForce (movement);
}
void LateUpdate ()
{
rb = GetComponent<Rigidbody> ();
Vector3 subtract = new Vector3 (0.0f, 0.0f, slowdown);
rb.AddForce (subtract);
}
void OnCollisionEnter (Collision other, Vector3 movement)
{
if (other.gameObject.CompareTag ("Ground"))
{
Jump (Vector3 movement);
}
}
void Jump(Vector3 movement)
{
if (jumping == true)
{
movement.y = jumpSpeed;
movement.y /= gravity;
}
}
}
Help is, of course, appreciated! Thanks!
Answer by zach-r-d · Jul 12, 2015 at 11:54 AM
The problem is the "Vector3" on line 45. When passing an argument to a function, writing the type is not necessary; it's only for declaring a variable (local, argument, or field). Change it to:
Jump (movement);
and it should work.
I tried it, but I got this: Assets/Scripts/PlayerController.cs(30,28): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
That's actually an unrelated problem, but in any case the solution is to put "new" in between the "=" and "Vector3".
Your answer
Follow this Question
Related Questions
Trying to call a variable from another script in C# 1 Answer
Multiple Cars not working 1 Answer
C# - Simple Optimization / Variable Declaration 1 Answer
Distribute terrain in zones 3 Answers