- Home /
mistake in script
First I want to ask this : I wrote that script and add it to player... but it doesn't work (C#) . could you please correct it for me?
using UnityEngine; using System.Collections;
public class Wipe : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
{
if (transform.position.x > 709)
transform.position = new Vector3(-1300, transform.position.y, transform.position.z);
}
{
if (transform.position.x < -1310)
transform.position = new Vector3(700, transform.position.y, transform.position.z);
}
}
}
The title of the question is too general, please edit / rename your question title to whatever the real question is about.
next: what error do you get, since it doesnt work? Unity has a Console window that shows the compiler errors.
What errors is the console throwing regarding your script? You can find the errors or warnings in the bottom left of the unity window. Also note that the brackets before and after your if statements are in the wrong spot. I don't think this is the current problem, but the brackets before each if statement should be after the actual if statement.
Beggreen and i had the same idea (he ninja'd me). See if his suggestion works.
I used this script for an Empty gameObject when I moved that it worked , but when I add it to maincamera it doesn't work!!!
Answer by BerggreenDK · Aug 05, 2011 at 12:07 AM
I think your brackets are wrongly placed?
Try this:
using UnityEngine;
using System.Collections;
public class Wipe : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (transform.position.x > 709)
{
transform.position = new Vector3(-1300, transform.position.y, transform.position.z);
}
if (transform.position.x < -1310)
{
transform.position = new Vector3(700, transform.position.y, transform.position.z);
}
}
}
Think of brackets {} like () in a piece of math.
You make a function with Multiply(a,b) etc. so the () follows the function.
Same goes for your IF structures.
IF (condition)
Now if the condition is meet, then you use the {} to encapsulate the things to happen.
Like
if (condition is true)
{
// do this
}
else // condition isnt true aka false
{
// do something else
}
Your answer
Follow this Question
Related Questions
Disable script. 3 Answers
Player movment script help 2 Answers
function Touch 5 Answers
Make player unable to shoot when reloading 3 Answers
Weird problem with gunscript 2 Answers