#FNAF CLONE

1 messages · Page 1 of 1 (latest)

hearty grail
#

isOn what

river sphinx
#

like isOnCloset isOnWindow

hearty grail
#

isOnWindow = true;

#

these were never the problem

river sphinx
#

private IEnumerator Appear(bool Bool, SpriteRenderer renderer, Sprite sprite)
{
yield return new WaitForSeconds(waitTime);

    Bool = true;

    renderer.sprite = sprite;
}
hearty grail
#

oh add ref

#

ref bool Bool

#

value types are copied and i forgot about that @_@

river sphinx
hearty grail
#

it basically points to the original value instead of copying it

river sphinx
#

it tells me that iterators cannot have ref in or out parameters

hearty grail
#

hmm... let me open VS

river sphinx
#

k

hearty grail
#

yep. never encountered that before so that's interesting

#

you could invoke it instead of making it an enumerator though

keen thicket
#

You cannot use ref parameter for IEnumerator because it can exist outside of stack

#

You’d use callback instead yes

river sphinx
#

so what should i use

keen thicket
#

Uhh you cannot use parameter at all for Invoke 😄

hearty grail
#

fucker

#

how come i've never had that problem in 5 years

#

am i a robot

keen thicket
#

We are all brains in a jar

river sphinx
#

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?

keen thicket
#

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

river sphinx
#

enum X
{ mybools
}

keen thicket
#

You could easily set it with e.g. myDict[myEnum] = true

hearty grail
#

that sounds worse than writing everything twice though

keen thicket
#

How so? 😄

hearty grail
#

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

keen thicket
#

Yeah I think he wants kind of state machine stuff?

hearty grail
#

more or less, yeah

#

state for animatronics and state for spots they can use

hearty grail
#

whatever solves this fuckery

river sphinx
#

i want to state that it can only be in one place at a time

hearty grail
#

first off yeah, make an enum

#

for these

#

public enum IsOn
{
Hidden,
Window,
Closet,
DoorRight,
DoorLeft,
BedFront,
BedBack,
}

^paste this outside of class

river sphinx
#

Ok

hearty grail
#

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

river sphinx
#

So i can Say if is Window It cannot be anywhere else

hearty grail
#

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

river sphinx
#

So if i spot him in the Window It should be something likes if(state == IsOn.Window && flashlight.isOn){do sum}

hearty grail
#

do sum = draw char? you still have to check if there's another char in that spot

river sphinx
#

Ye

hearty grail
#

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

river sphinx
#

Oh ok

#

Thanks for the help

hearty grail
#

@ me once the new knowledge finished sinking in and you're done rewriting stuff

river sphinx
#

ok thank you

hearty grail
#

FNAF CLONE

river sphinx
#

@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

river sphinx
#

Nvm solved it

hearty grail
#

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.

hearty grail
#
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


}
hearty grail
#
//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

river sphinx
#

Time Is the reference to the script current Time Is the value fron the script

hearty grail
#

that's a weird way to break it apart

#

in any case, stay away from Update()

river sphinx
#

Ok

hearty grail
#

it's only supposed to be used for stuff that's actually updated every frame and doesn't care about framerate, and you don't need that

#

e.g. visuals of doors closing can be in update