- Home /
Namespace error with my jump code
So I am trying to make my character jump, here is my code so far... the problem is I am getting an error that says " A namespace can only contain types and namespace declarations" it says the error is in line 49
using UnityEngine; using System.Collections;
public class robot : MonoBehaviour {
public float maxSpeed = 10f;
bool fasingRite = true;
Animator anim;
private int jumpheight = 500;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate ()
{
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if (move < 0 &&!fasingRite)
Flip ();
else if(move > 0 && fasingRite)
Flip ();
if (Input.GetButtonDown("Jump") || Input.GetKey("space")){
}
void Flip ()
{
fasingRite = !fasingRite;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
void Jump (){ rigidbody.AddForce(new Vector3(0, jumpheight,0), ForceMode.Force);
Answer by Sildaekar · Mar 12, 2014 at 04:13 AM
Please refrain from asking the same question multiple times. Here is the same answer I provided on your other question:
It looks as though your script has an extra closing bracket. Look on line 49 (or maybe it's on 48) and remove that bracket.
void Flip ()
{
fasingRite = !fasingRite;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
The last bracket there is closing out your class forcing everything below it to drop into the namespace. This is what is throwing the error.
If this answers your questions please don't forget to mark this answer :)
Your answer
Follow this Question
Related Questions
Hovering Cube on CapsLock? 2 Answers
3rd person controller, jump Error 1 Answer
Head bob script overrides ability to jump,Not able to jump with Head bobbing script 1 Answer
Character Controller problem with enum 0 Answers
Can't jump in C# 1 Answer