#hm it still doesn t work
1 messages · Page 1 of 1 (latest)
Hmm...
just in inspect?
try setting the variable public and set it in inspect. It really should work with that.
variable1 public and set in inspect
script 2 access script 1 variable and change it at start
hold on
in script 2. at start. You reference script 1 right?
have you referenced it in the inspector?
Show me a pic of the script in inspector
Ammo rotation = Script 2
Ammo Script = Script_1 (var name from Script1, so from my first script, Ammo)
Ammo Flying = Var2
Okay, and now show the inspector of the Ammo object you dragged in
Ammo(script) = Script1
AmmoIsFlying = Var1
Okay so what's the problem
They're both 0
just
that seems right
hold on
and when game starts it'll be the value of ammo is flying
if its 0 var 2 will also be 0
these are the scripts ingame
ammoflying (Var2) isn't changing to 1
it stays at 0
hold on
You only set var2 in Start. Changing it later doesn't do anything to it
oh wait
private class Ammo() {
//Set in inspector
private float variable1;
}
And the second
private class AmmoRotation() {
//Set in inspector
public float variable2;
//reference to script
public Ammo ammoScipt;
private void SyncVariables() {
variable2 = ammoScript.variable1;
}
}
YOU DIDN'T PUT IT IN UPDATE?!
i will cry. These functions go into update btw
update returns each fram
Awake and Start at beginning
Also this is wholly unnecessary. Why even have var2 at all
only once
Just use the var from the reference
yeah I just found out.
now it works
Just remove Ammo Is Flying as a variable, and use Ammo.AmmoFlying instead
well. idk what your gon do with that but cool
use camel case haha
it's amazing
I suggest you take a video on UNITY BASICS
it'll get you comfortable with the framework
Ok... Close thread?
lmk when to do
yeah. I'm pretty good in other things, but passing variable's through scripts was new to me. I never used it before, now almost at the end of my game I had to use it
ohhh kk
A few basic ways to get references in Unity.
Directly-
GetComponent 0:38
/GetComponentInChildren
/GetComponentInParent
Public Variable- 3:00
Find- 5:01
Find 5:39 (by name)
FindWithTag 6:14 (by tag)
FindObjectOfType 6:51 (by component)
Interaction- 7:15
OnCollisionEnter
/OnTriggerEnter
but anyways thnx for the help
thnx
now I need to fix the 2 last problems and it's finished