- Home /
Question by
Hazza11 · Sep 16, 2020 at 07:53 PM ·
1st personobject movementholding
Pick up and object with a Rigidbody,Pickup object with Rigidbody and hold it
I'm trying to get it so that the character can pick up a cube, that they then can jump on while still holding. But I can't find a way to do that. Here's the script I currently have: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MoveObjectScript : MonoBehaviour { public GameObject item; public GameObject tempParent; public Transform guide;
// Start is called before the first frame update
void Start()
{
item.GetComponent<Rigidbody>().useGravity = true;
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
item.GetComponent<Rigidbody>().useGravity = false;
item.GetComponent<Rigidbody>().isKinematic = true;
item.transform.position = guide.transform.position;
item.transform.position = guide.transform.rotation;
item.transform.parent = tempParent.transform;
}
private void OnMouseUp()
{
item.GetComponent<Rigidbody>().useGravity = true;
item.GetComponent<Rigidbody>().isKinematic = false;
item.transform.parent = null;
item.transform.position = guide.transform.position;
}
} ,
Comment
Your answer
Follow this Question
Related Questions
problem with mechanim 0 Answers
Implement Video Ad Skip Forfeit Reward Screen 0 Answers
Looking Up/Down,looking up/down 0 Answers