hi
im quite new to unity, and i am trying to build a mobile game. if someone can point me in the right direction i would really appreciate it. i am getting error CS0103: The name `pos’ does not exist in the current context. this is for “Stop”, “moveright”,“moveleft”,“pos” and so on. as im fairly new to unity and c# could you explain why these errors are occurring and how i can resolve this. the code i am using is below:
using UnityEngine;
using System.Collections;
public class CubeControl : MonoBehaviour {
void Update() {
float x = Input.GetAxis (“Horizontal”);
if (x == 0) {
Stop ();
} else if (x > 0) {
MoveRight ();
} else if (x < 0) {
MoveLeft ();
}
CubeControl = transform.position; //left//right
CubeControl.x = Mathf.Clamp (CubeControl.x, “yourboundryminto”, “Yourboundrymax”);
transform.position = CubeControl;
}
}
Please insert code properly: https://forum.unity3d.com/threads/using-code-tags-properly.134625/
You’re trying to run a method MoveRight, but you haven’t specified what it is.
For example:
void Start()
{
SpamTheConsole(); //on start, run this function
}
//declare what you want to do!
void SpamTheConsole()
{
Debug.Log("Your console has just been spammed!"); //do something
}
ok, cheers so how do i go about specifying it?
basically i have a gameobject named “block” with two long cubes next to each other with a gap between them. now when a user touches the screen and drags left or right the block also moves in that direction. now i am trying to setup a boundary so they can go up to a certain amount in the left or right direction. however how can i code this?
if you could explain it to me it would be great.
thanks
You’ve got a ton of problems in that snippet. Frankly, I’d suggest getting a better grip on the C# language and programming in general before trying to tackle game creation. When you’re ready for the latter - start here: Learn
1 Like
right just to update everyone i have solved it, works perfectly now. unfortunately that code above was no good, rewrote it and got it working. happy days