I’ve recently tried to get back into Unity, and for now, want to spawn a “hook” for a spring joint when the player touches the floor for a movement mechanic, but I’m having trouble enabling the spring in the first place.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HookSpawner : MonoBehaviour //In a script parented to the floor
{
public GameObject Player; //I pass the gameobject for the player through
void OnCollisionEnter2D(Collision2D other)//And on collision with eachother
{
Debug.Log("Pixel has touched a floor tile");
Player.GetComponent<SpringJoint2D>().Enable(true);//* The floor SHOULD spawn the hook
}
}
Everywhere online tells me something like this should work just fine, but the last line* throws an error that “SpringJoint2D” does not contain a definition for “Enable”. So It’s looking for an “Enable” method, not an “Enable” property.
But when I google that I only see guides on how to enable a property for a component within the same gameobject…