- Home /
Question by
username33344444 · Mar 22, 2020 at 12:36 AM ·
c#booleanshealth
Can anyone find the problem with this code?
I'm trying to connect a bool from a script called "Inventory" to "Button2" so that if 5 coins are collected, the button to the door is allowed to be opened. I have tried the // stuff in the Void Start also, but this gives no result.
devenv-cw6aqh6zrp.png
(17.8 kB)
devenv-r5inf8hwqv.png
(13.5 kB)
Comment
Please use the 'code' sample to post your code, screenshots of code is uncopyable, so no one can test your code without having to re-write the whole lot.
Answer by Arshww · Mar 22, 2020 at 02:01 AM
Try modifying the OnMouseDown() in the Button2 script, like this:
public void OnMouseDown()
{
bool canOpen = DoorOpenable.GetComponent<Inventory>().CanOpenDoor;
if(canOpen)
{
// Plays the audio clip...
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
targetDoor3.GetComponent<Door3>().OpenDoor();
targetDoor4.GetComponent<Door3>().OpenDoor();
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Setting the texture quality in HDRP using C# 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
Enemy Health GUI Issues 0 Answers