Can't change bool from different script directly or through voids,bool won't change from another script no matter changing directly or using public voids...
I've been looking through the internet for days on end without an answer to my question, I don't know if I'm being dumb here or this is a more deeper problem...
So my intensions are there is a hinge joint following my mouse if a bool is false, and when true, flops around... (making an interactive crafting system). On mouse down on an object, the bool (from the hinge script) is supposed to be set true and a hinge joint is set to that object, and on release, the hinge joint is disabled (by setting connected body to itself) and the bool is supposed to be set to false. (the pointer and all objects have separate scripts). Here's the problem, when trying to change the "move" bool, it completely fails and doesn't change (I've narrowed it down to directly to where the bool is trying to be changed using debug.log), even if I change it directly by using [the script].[the variable] = false, or even calling a void [the script].[the void](), but it just doesn't work, there are no syntax which is making me believe it's unity's fault.
Please ignore my dumb and unclean scripting...
Script on hinge:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
public class Hinge : MonoBehaviour
{
private Vector2 MousePosition;
public float speed, distance;
private Rigidbody2D rb;
public bool Move;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
MousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
distance = Vector2.Distance(MousePosition, this.transform.position);
if (Move == true)
{
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
diff.Normalize();
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 45);
}
else
{
transform.position = MousePosition;
}
}
void FixedUpdate()
{
if (Move == true)
{
rb.velocity = Vector2.zero;
rb.AddRelativeForce((Vector2.up + Vector2.right).normalized * distance * speed, ForceMode2D.Force);
}
}
}
And now here's the script that all draggable objects have:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
public class Drag : MonoBehaviour
{
public HingeJoint2D hinge;
public Rigidbody2D ThisRB, HingeRB;
public Hinge hingy;
void OnMouseDown()
{
hingy.Move = true;
hinge.connectedBody = ThisRB;
}
void OnMouseUp()
{
hingy.Move = false;
hinge.connectedBody = HingeRB;
}
}
Your answer
