C
C#8mo ago
ULTIMA

Lever to open a door

hey im having trouble with a school project and i have a code that refuses to work and i need some help or tips on this. i have a lever, and a door, the lever is the parent object(more specifically the LeverTrigger) and the door is a child object within. i want to hit the lever with E and have the door run its animation to open. any thoughts on my code (i am aware its not Functional) https://paste.mod.gg/ginabssqkbah/0
BlazeBin - ginabssqkbah
A tool for sharing your source code with the world!
12 Replies
Jimmacle
Jimmacle8mo ago
no DMs, use $paste
MODiX
MODiX8mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
ULTIMA
ULTIMAOP8mo ago
thanks
Nefario
Nefario8mo ago
do you already drag and drop this?
public int leverNumber;/
public int leverNumber;/
from what i can tell, if player in range near lever, player can interact it with get button E, then if player press E while inrange then do animation. if your code really doesnt work, try to debug it using Unity Debug Mode or you can always count write a comment there. on each function. to see whather or not it works. and also i want to ask you question where this script attach to? is it on the Lever or Player itself?, if it's on the lever, why there's Input.GetKeyDown? on the lever?
FusedQyou
FusedQyou8mo ago
So what is the issue? You shared the code and explained what you want, but what exactly is the issue that would prevent you from doing this? This code looks fine and would work
ULTIMA
ULTIMAOP8mo ago
Im getting an error code everytime i try to interact with the lever, not sure what it was off the top of my head but ill be working on it this afternoon and trying out the suggestions
FusedQyou
FusedQyou8mo ago
Alright, please send the error as soon as you can
ULTIMA
ULTIMAOP8mo ago
NullReferenceException: Object reference not set to an instance of an object thats the error and it links to this code, " leverAnimator.SetTrigger("LeverTrigger" + leverNumber);" ps. the code is connected to the lever not the player also the door is set, and the lever and door numbers are set although door number doesnt change anything could it be the animator? nvm i see what is wrong i need to get the lever animator i think
FusedQyou
FusedQyou8mo ago
Probably But this still is not enough Please share the full error including stacktrace
ULTIMA
ULTIMAOP8mo ago
error has been fixed but now i have another problem lol Parameter 'OpenClose1' does not exist. UnityEngine.Animator:SetTrigger (string) LeverSwitch:Update () (at Assets/ScriptsU/LeverSwitch.cs:32) i have two animations in different child objects, and it only wants to take from one even though i get component twice
ULTIMA
ULTIMAOP8mo ago
BlazeBin - qxqitdakbqas
A tool for sharing your source code with the world!
ULTIMA
ULTIMAOP8mo ago
updated code
Want results from more Discord servers?
Add your server