#hi how do i call a function from a
1 messages · Page 1 of 1 (latest)
first of all import the script
public <OtherScriptName> <VarName>
the you can reach the variables and methods of said script by using <VarName>.<MethodName>()
copy-pasted it here
i have in script 1 (i want to activate script 1) public static void Roles() {}..... and in script 2 i have (script1).Roles()
also, dont forget to attach the target script in the scene in unity
but that doesnt seem to work
ok
this is a little compicated XD
never used that bedore
it took me a while to figure out, but once you have it its quite easy
lemme try it
quick question. the public static bool for example. i can use that via other script right? with no problem?
do you need it to be static?
i dont know what static means.... i thaut it was so you can reach it via other script
thats what public does
imma figggure it out i think.. im trying this now
I am learning myself and from experience, I have neved had to use a static method
mmh... ok
thats why I doubted that you need it
how did it go?
npnp
this is kinda hard to figgure out.. got a blackout.. but ill get there
alright, whats the name of your script 1?
I will pretend that its called Script1
in the header of script 2 (where you define all the variables that you will be using) you want to put
public Script1 script1
and then you can call the method easily anywhere in script 2 by using script1.Roles()
last step is finding the script 2 on the object you have attached it to, fining the script1 variable and attaching the Script1 there
lemme pull up my own script, one sec
hope this helps
yeah i did that
that works now
its just i am trying somthing new without a tuturial.. and i cant get it to work
xD
its taking me so long
what are you trying to do? maybe I can help
Im on a train, so that isnt possible, sorry
oh ok
emmm...
i wanna make roles.. i need 2. so i want role Hunter and Runner... and i need to assighn it to the player and like there can only be 1 hunter
but my code is sooooo messy
so i got this
its multiplayer
so that all new for me anyway
im testing it now
do you want to choose both of them at the start of the game?
for now i want it so it chooses when i press p
i am like on the edge of removing most of my scripts and starting over
what I meant is, do they get their roles assigned at the same time and for the entire game?
alright
Im not saying its the best solution out there, but my solution would be putting all the players in a list
more info: you start game, fill in name and press connect,, then when connected to server it loads in a map scene where the player is spawned in
picking a random one and making it the hunter
ohhhhh
then removing the hunter from the list
and then looping through the list and making everybody the runner
yeah...
hope that makes sense 😄
i just dont know how to tell my script to make a list and choose 1 xDDD
it does..
i can use youtube for that i think
the list is defined by
public List<GameObject> variablename;
imma search it up xD
thanks
(if you need to explain via text you will have to whrite so much, dont wanna do that to you)
choosing a random thing on the list:
variablename[Random.Range(0,variablename.Count)]
this should work
maybe the C in count needs to be capital
ok hahaha
dont take it as me telling you that you need to start over... I just believe that this is much cleaner and easier to build on
yeah, was planning to anyway, i cant find shit on this code now
its spread over like 3 scripts xD
and as for the rese - you can add all the players back into the list again, removing their tags and calling the method Roles() again
Aye, programming can be quite mentally exhausting... I'm taking a break myself, I have been working for the past 5 hours lol