im trying to do a hook gun but unity sends me an error, "
Assets\Scripts\player\HookDetector.cs(15,13): error CS0176: Member ‘GrapplingGun.hooked’ cannot be accessed with an instance reference; qualify it with a type name instead"
the problem is with two codes
public class GrapplingGun : MonoBehaviour
{
public GameObject hook;
public GameObject hookHolder;
public float hookTravelSpeed;
public float playerTravelSped;
public static bool fired;
public bool hooked;
public float maxDistance;
private float currentDistance;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Q) && fired == false)
fired = true;
if (fired==true && hooked == false)
{
hook.transform.Translate(Vector3.forward * Time.deltaTime * hookTravelSpeed);
currentDistance = Vector3.Distance(transform.position, hook.transform.position);
if (currentDistance>=maxDistance)
ReturnHook();
}
if (hooked==true)
{
transform.position = Vector3.MoveTowards(transform.position, hook.transform.position, playerTravelSped);
float distanceToHook = Vector3.Distance(transform.position, hook.transform.position);
if (distanceToHook<1)
{
ReturnHook();
}
}
void ReturnHook()
{
hook.transform.position = hookHolder.transform.position;
fired = false;
hooked = false;
}
}
}
_____________the second one, wich is wrong
{
public GameObject personaje;
private void OnTriggerEnter(Collider other)
{
if (other.tag=="Hookeable")
{
personaje.GetComponent<GrapplingGun>().hooked = true;
}
}
}