It would seem like my GetComponent Script isn’t working…
So, I have 2 different scripts, one which is for my spikes in this case, and another which is for my lever.
They look like this(unrelated part taken out):
Lever:
public class LLever : MonoBehaviour
{
public bool down = false;
public GameObject mhm;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(interactKey) && isInRange==true)
{
if(down == false)
{
mhm.GetComponent<SPike>().yfs = false;
}
if(down == true)
{
mhm.GetComponent<SPike>().yfs = false
}
}
Spikes:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SPike : MonoBehaviour
{
public Rigidbody2D rb;
public bool yfs = false;
void Start()
{
}
int k = 0;
void Update()
{
}
private void FixedUpdate()
{
Vector2 a = new Vector2(0, 10);
if (yfs == false && k==0)
{
rb.position = rb.position + a ;
k = 1;
return;
}
else if (yfs == true && k==1)
{
k = 0;
rb.position = rb.position - a;
return;
}
}
}
Now, when I interact with the Lever, the bool “yfs” doesn’t change in the Script for the Spikes!
Any help is welcome,
Thanks in advence!