Question by
monster T · Feb 09, 2016 at 06:47 PM ·
scripting problemerror message
Please Help Me: Assets/Scripts/PlayerControaller.cs(34,33): error CS8025: Parsing error
using UnityEngine; using System.Collections;
[RequireComponent(typeof(PlayerPhysics))] public class PlayerControaller : MonoBehaviour {
//Player Handling
public float speed = 8 ;
public float acceleration = 12 ;
private float currrentSpeed;
private float targetSpeed;
private Vector2 amountToMove;
private PlayerPhysics playerPhysics;
void Start () {
playerPhysics = GetComponent<PlayerPhysics> ();
}
void Update () {
targetSpeed = Input.GetAxisRaw ("Horizontal") * speed;
currrentSpeed = IncrementTowards (currrentSpeed, targetSpeed, acceleration);
amountToMove = new Vector2 (currrentSpeed, 0);
}
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a) {
if (n == target) {
return n;
} else {
float dir = Mathf.Sign (target - n) // must n be increased or decreased to get closer to target
+= a * Time.deltaTime * dir;
return (dir == Mathf.Sign (target - n)) ? n : target // if n has now passed target then return target, otherwise return n
;
Comment
Answer by Landern · Feb 09, 2016 at 06:49 PM
Your code is completely hacked up, line endings/terminations after comments, missing curly braces, i've made some assumptions and tried to line up various arithmetic that was going on in IncrementTowards
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PlayerPhysics))]
public class PlayerControaller : MonoBehaviour {
//Player Handling
public float speed = 8;
public float acceleration = 12;
private float currrentSpeed;
private float targetSpeed;
private Vector2 amountToMove;
private PlayerPhysics playerPhysics;
void Start () {
playerPhysics = GetComponent<PlayerPhysics> ();
}
void Update () {
targetSpeed = Input.GetAxisRaw ("Horizontal") * speed;
currrentSpeed = IncrementTowards (currrentSpeed, targetSpeed, acceleration);
amountToMove = new Vector2 (currrentSpeed, 0);
}
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a) {
if (n == target) {
return n;
} else {
float dir = Mathf.Sign (target - n);
target += a * Time.deltaTime * dir;
return (dir == Mathf.Sign (target - n)) ? n : target;
}
}
}
Your answer
Follow this Question
Related Questions
Particle System trigger script not working,Particle system trigger script not working 0 Answers
Need help with error CS0029 and error CS0118 3 Answers
Referencing and Executing Script Can't Be Done due to Not Being A Statement 0 Answers
NullReferenceException: Object reference not set to an instance of an object 1 Answer