#FNAF CLONE
1 messages · Page 1 of 1 (latest)
like isOnCloset isOnWindow
private IEnumerator Appear(bool Bool, SpriteRenderer renderer, Sprite sprite)
{
yield return new WaitForSeconds(waitTime);
Bool = true;
renderer.sprite = sprite;
}
can you explain what it does?
it basically points to the original value instead of copying it
it tells me that iterators cannot have ref in or out parameters
hmm... let me open VS
k
yep. never encountered that before so that's interesting
you could invoke it instead of making it an enumerator though
You cannot use ref parameter for IEnumerator because it can exist outside of stack
You’d use callback instead yes
so what should i use
Uhh you cannot use parameter at all for Invoke 😄
We are all brains in a jar
void GoAway(bool Cum, SpriteRenderer renderer, Sprite sprite)
{
Cum = true;
renderer.sprite = sprite;
}
cant i jjust do it like this
then invoke it after x seconds?
I would define enum for all your bool things
Then make an array or a dictionary to map enum to bools
Then pass the enum as parameter
enum X
{ mybools
}
You could easily set it with e.g. myDict[myEnum] = true
that sounds worse than writing everything twice though
How so? 😄
i looked at my stuff and it seems like the reason i never had problems is that everything is inside its' own class instance
but it has reason to be split up, doing it here would be worse than writing everything twice again
Yeah I think he wants kind of state machine stuff?
exactly
whatever solves this fuckery
i want to state that it can only be in one place at a time
first off yeah, make an enum
for these
public enum IsOn
{
Hidden,
Window,
Closet,
DoorRight,
DoorLeft,
BedFront,
BedBack,
}
^paste this outside of class
Ok
then inside class
IsOn state = Hidden;
then you can just compare and set state
although wait...
you'll still need these bools, but to check if the place is occupied, not the position of char
So i can Say if is Window It cannot be anywhere else
yeah, if (state == IsOn.Window) {} that means it's nowhere else assuming you set it correctly
and you'll still need to figure out how to check if it's occupied.
you can either set the bool or check if any other char is also on window
So if i spot him in the Window It should be something likes if(state == IsOn.Window && flashlight.isOn){do sum}
do sum = draw char? you still have to check if there's another char in that spot
Ye
so you'll still need to make a static bool for when window is occupied
and in that case the better idea would be to check if it's occupied whenever you turn on flashlight
and do fail jumpscare separately
@ me once the new knowledge finished sinking in and you're done rewriting stuff
ok thank you
FNAF CLONE
@hearty grail so i tried redesining the script based on the new knowledge
but now unity freezes every time current is 1
i think this has to do with the state check function
Nvm solved it
unbroken while loops, nasty
@river sphinx do you actually need all 6 coroutines starting?
you only need to start 1 coroutine which decides where it'll appear
and isOn is already the state of where it is
and the wet spaghetti at start got even worse somehow
this is also nasty, why are you checking time twice?
if monster can appear, start a coroutine that decides where it is, and set bool of that place as taken.
public enum IsOn
{
Hidden = 0,
Window = 1,
Closet = 2,
DoorRight = 3,
DoorLeft = 4,
BedFront = 5,
BedBack = 6,
}
using System.Collections;
using UnityEngine;
public class Monster : MonoBehaviour
{ public IsOn currentlocation = IsOn.Hidden;
static bool[] locationTaken = new bool[7]; //can be moved to location script
void moveIn() //shouldn't be called if already visible. shouldn't be called on update.
{
if(time == 6) { Debug.LogError("night over, but this fucker is still attempting to move"); return; }
locationTaken[(int)currentlocation] = false;
if (!locationTaken[1] && time == 1) { currentlocation = IsOn.Window; locationTaken[1] = true; }
else if(!locationTaken[2] && time >= 1) { currentlocation = IsOn.Closet; locationTaken[2] = true; }
else if(!locationTaken[3] && time >= 2) { currentlocation = IsOn.DoorRight; locationTaken[3] = true; }
else if(!locationTaken[4] && time >= 3) { currentlocation = IsOn.DoorLeft; locationTaken[4] = true; }
else if(!locationTaken[6] && time >= 5) { currentlocation = IsOn.BedBack; locationTaken[6] = true; }
}
private void Awake() //cache timers if they don't change
{ wt = new WaitForSeconds(waitTime); //can multiply by difficulty setting
lt = new WaitForSeconds(lookTime);
}
public float waitTime; WaitForSeconds wt; //do different monsters have different wait/look times?
public float lookTime; WaitForSeconds lt; //if it's a global setting then make it static and initialize only once
}
//cont.. monster
private IEnumerator Appear()
{
yield return wt; //wait...
switch (currentlocation)
{
case IsOn.Window: { if (time == 4 || time == 5) { window.sprite = windowAndMonsterBlood; }
else { window.sprite = windowAndMonster; } break; }
case IsOn.Closet: { closet.sprite = closetAndMonster; break; }
case IsOn.DoorRight: { doorRight.sprite = doorAndMonster; break; }
case IsOn.DoorLeft: { doorLeft.sprite = doorAndMonster; break; }
//
case IsOn.BedBack: { back.sprite = backMonster; break; }
}
}
once monster has moved in...
when player looks at location, check if that location is taken...
if true, check which monster and call Monster[?].StartCoroutine(Monster[?].Appear());
also, time.currentTime and time... are they different? it's fucking confusing
Time Is the reference to the script current Time Is the value fron the script
Ok