Hi guys,
I’m using unity’s 2d features to make my game and i’m getting the cs1525 error, upon researching the error it seems that most of the time the error is due to miss-typing or the miss-placement of code, however I cant see any problems with my code.
using UnityEngine;
using System.Collections;
public class playerMove : MonoBehaviour {
//declare the max speed
public float maxSpeed= 4.5f;
// the player character is facing to the right by default
public bool facingRight= true;
Animator anim;
void Start ()
{
anim= GetComponent<Animator>();
}
void FixedUpdate ()
{
public float playerMove = Input.acceleration.x; //move equals acceleration.
//used to be less than neg
if(move < -0.2f || move > 0.2f) // if the device is tilted so far in either direction
{
anim.SetFloat ("Speed", Mathf.Abs(playerMove)); //set the Speed parameter to the value after the comma
rigidbody2D.velocity= new Vector2 (playerMove * maxSpeed, rigidbody2D.velocity.y); //declare the x and y of the rigid body
if(playerMove > 0 && !facingRight) // if move is more than 0 and the player is NOT facing right
Flip(); //see flip below
else if(playerMove < 0 && facingRight) //if move is less than 0 and facing right
Flip(); //see flip below
}
else if(playerMove > -0.1f || playerMove < 0.2f)
{
anim.SetFloat ("Speed", 0);
rigidbody2D.velocity= new Vector2 (0,0);
}
}
void Flip()
{
facingRight= !facingRight;
Vector3 theScale= transform.localScale;
theScale.x *= -1;
transform.localScale= theScale;
}
}
the problem is with this particular line - public float playerMove = Input.acceleration.x; //move equals acceleration. (line 20)
It seems to have a problem with the public part before the float. can anyone see why this would be a problem?
I need to access this float from another separate script so I need this float to be public.
Cheers guys,
Mark