- Home /
Question by
ProfMonkey07 · Jul 14, 2020 at 05:44 PM ·
c#scripting problembuggrab
grab script not working
for my game I created a grab object script, that script works fine. but later I tried redoing it and making it better but now its not working. could someone help me figure out hoe to fix this? public class grab : MonoBehaviour { public bool holding = false; public Rigidbody rb; public Transform t; public GameObject item; public Transform theDest; public LayerMask yesHit; public Transform nullDef; public GameObject nullDif; public Transform defaultRot;
void FixedUpdate()
{
if (holding = false)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 5, yesHit))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
t = hit.transform;
item = hit.collider.gameObject;
}
else
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 5, Color.white);
t = nullDef;
item = nullDif;
rb = nullDif.GetComponent<Rigidbody>();
}
rb.useGravity = true;
}
else
{
if (holding = true)
{
t.rotation = defaultRot.rotation;
t.transform.SetParent(theDest);
t.position = theDest.position;
rb.useGravity = false;
}
}
}
// Update is called once per frame
void Update()
{
if (holding = false)
{
if (Input.GetButtonDown("Fire1"))
{
holding = true;
}
}
else
{
if (Input.GetMouseButtonDown(1))
{
holding = false;
}
}
}
}
Comment