- Home /
Trouble grabbing and holding a cube.
when ever you import standard assets, if you go to the scripts section,
and under general there is a script for dragging a rigid body,
thats what i was talking about here.
Hi, i have been working on this script for about 5 hours now because i really didnt like the standard dragging rigid body script,
using UnityEngine;
using System.Collections;
public class Drag : MonoBehaviour {
RaycastHit hit;
public Transform Box;
public bool ready;
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("box");
Box = go.transform;
}
// Update is called once per frame
void Update () {
int x = Screen.width/2;
int y = Screen.height/2;
Ray fly = camera.ScreenPointToRay(new Vector3(x, y));
if(Physics.Raycast(fly, out hit)){
if(hit.rigidbody){
if(ready == true){
Box.position = hit.point;
}
}
}
if(ready == false){
if(Input.GetMouseButtonDown(0)){
ready = true;
}
}
else{
if(Input.GetMouseButtonDown(0)){
ready = false;
}
}
}
void OnGUI(){
if(ready == true){
GUI.Box(new Rect(100,100,50,50), "ready");
}
}
}
The main problem that im having with the script is that the box will come flying at my face when im facing it and have clicked the mouse, but there isnt any way of stopping it a few inches away like the source games, any advice would be helpful.
Sorry bout the script i couldnt find the script input section.
click EDIT
highlight your code !
noteice teh small "CODE" button, it has strange 010 101 pattern on it
what do you mean by "the standard dragging rigid body script" ???