So I am trying to get my code to disable the active state of a collider to allow the player to pass through it momentarily. Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollisionEnabler : MonoBehaviour
{
public bool floorActiveState;
private PlayerController playerController;
void Start ()
{
playerController = GetComponent<PlayerController> ();
}
void Update ()
{
if (playerController.touchingFloor == false)
{
Collider.enabled = false;
floorActiveState = false;
}
else
{
Collider.enabled = true;
floorActiveState = true;
}
}
}
You have to get the collider using GetComponent().enabled. Assuming that is the collider on that gameobject you want to disable.
Okay I am really new to scripting; This game I am making is my first. I have no idea what youre taking about, where on earth do I put that in my code??
He meant instead of “Collider.enabled”.
At least one of the fields should be static.
But you didn’t post which line is causing you problems.
public static bool floorActiveState;
//or
private static PlayerController playerController;
//or both
‘Collider’ is the class. Whereas, what @Brathnann wrote will get you the instance of the class (script) on your game object.
FMark92:
At least one of the fields should be static.
But you didn’t post which line is causing you problems.
public static bool floorActiveState;
//or
private static PlayerController playerController;
//or both
I don’t think that’s it. He was trying to call “Collider.enabled”