- Home /
This question was
closed Jul 20, 2016 at 06:43 PM by
matthrewp for the following reason:
The question is answered, right answer was accepted
Question by
matthrewp · Jul 12, 2016 at 03:03 PM ·
c#scripting problemif-statements
If statement randomly not working
I have this if statement, set up the same way as all my other ones (near the bottom), but it's not working. Why?
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject pBody;
public Vector3 offset;
public static bool Increase;
// Use this for initialization
void Start() {
Increase = false;
offset = transform.position - pBody.transform.position;
}
// Update is called once per frame
void Update() {
transform.position = pBody.transform.position + offset;
}
if (Increase == true){
//some action
}
}
I keep getting these errors:
Assets/Scripts/CameraController.cs(30,6): error CS1519: Unexpected symbol `if' in class, struct, or interface member declaration
Assets/Scripts/CameraController.cs(30,19): error CS1519: Unexpected symbol `==' in class, struct, or interface member declaration
Assets/Scripts/CameraController.cs(36,1): error CS8025: Parsing error
Comment
Best Answer
Answer by tanoshimi · Jul 12, 2016 at 03:14 PM
Because it's not contained within a method. Is it meant to be in Update? Check your brackets.
Wow. I completely overlooked that. I guess it's just luck my other if statements have been in a method.
Follow this Question
Related Questions
If condition true but code is not executed 0 Answers
Update within an if statement not working? 3 Answers
Problem with transform.LookAt and if statement 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers