Question by
SmartWarpSTUDIO · Aug 26, 2017 at 01:47 PM ·
c#beginnerhealth
What is wrong with my code...watched an unity tutorial and I keep forgetting everything!
here's the screenshot:
screenshot-42.png
(118.4 kB)
Comment
Answer by Positive7 · Aug 26, 2017 at 02:32 PM
disVar
is only initialized inAwake();
you should create a fieldprivate int disVar;
In LateUpdate
if(disVar = int 42);
should beif(disVar == 42)
without;
at the end of the lineLateUpdate is never closed with a curling brackets
}
What do you mean by "LateUpdate is never closed with a curling brackets }"
I think I fixed it a bit btw but now it will only say "INCORRECT" in the console
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightSwitch : $$anonymous$$onoBehaviour {
private int disVar;
void Awake () {int disVar = Plus2 (6, 7);
Debug.Log (disVar);}
public Light myLight;
int Plus2 (int di1, int di2) {int returnValue = di1 * di2;
return returnValue;}
void Update() {if (disVar == 42) {
Debug.Log("CORRECT");
}
else {Debug.Log("INCORRECT");}}
}
void Awake()
{
disVar = Plus2(6, 7);
Debug.Log(disVar);
}
Your answer
Follow this Question
Related Questions
C# Script question 0 Answers
Player animation FSM stopped working 0 Answers
AnimationComplete() Error 0 Answers
Certain scripts that are attached does not work after build, scene change and closing unity 0 Answers
can't damage spawned prefab 1 Answer