- Home /
Control Object Script
Hello guys I was writing this script for controlling a second object after a PARTICULAR TIME LIMIT.
What I did was used the drag and drop object script(using mouse) and then used a collision script with a destroy script and simple timer but as soon as the cube collides the sphere gets destroyed and the timer does not work. And I don't know how to link the destroy script to take control of the Bigger sphere after the inner sphere is destroyed.
So I want 4 things :-
- A script for taking control of another object after the first is destroyed.
- Possible suggestions!
- A way to link the the scripts.
- Why the timer is not working in the collider script?
Please help me I am stuck in making of my first game!
Drag and Drop Script
var spring = 50.0; var damper = 5.0; var drag = 10.0; var angularDrag = 5.0; var distance = 0.2; var attachToCenterOfMass = false;</p> <p>private var springJoint : SpringJoint;</p> <p>function Update () { // Make sure the user pressed the mouse down if (!Input.GetMouseButtonDown (0)) return;</p> <pre><code>var mainCamera = FindCamera(); // We need to actually hit an object var hit : RaycastHit; if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), hit, 100)) return; // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) return; if (!springJoint) { var go = new GameObject("Rigidbody dragger"); var body : Rigidbody = go.AddComponent ("Rigidbody") as Rigidbody; springJoint = go.AddComponent ("SpringJoint"); body.isKinematic = true; } springJoint.transform.position = hit.point; if (attachToCenterOfMass) { var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else { springJoint.anchor = Vector3.zero; } springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = hit.rigidbody; StartCoroutine ("DragObject", hit.distance); </code></pre> <p>}</p> <p>function DragObject (distance : float) { var oldDrag = springJoint.connectedBody.drag; var oldAngularDrag = springJoint.connectedBody.angularDrag; springJoint.connectedBody.drag = drag; springJoint.connectedBody.angularDrag = angularDrag; var mainCamera = FindCamera(); while (Input.GetMouseButton (0)) { var ray = mainCamera.ScreenPointToRay (Input.mousePosition); springJoint.transform.position = ray.GetPoint(distance); yield; } if (springJoint.connectedBody) { springJoint.connectedBody.drag = oldDrag; springJoint.connectedBody.angularDrag = oldAngularDrag; springJoint.connectedBody = null; } }</p> <p>function FindCamera () { if (camera) return camera; else return Camera.main; }
Collider Script for inner sphere to get destroyed with a particle emitter and simple timer
var booms : ParticleEmitter; function OnCollisionEnter(theCollision : Collision) {
if(theCollision.gameObject.name == "Sphere") { Instantiate(booms, transform.position, transform.rotation);
Destroy(gameObject.Find("Sphere"),3);
} }
Avichal Singh
Dsksupinfogame
Your answer
Follow this Question
Related Questions
Swapping 2 objects positions when one is dragged into the other 1 Answer
Why is there still drag when drag is 0? 0 Answers
Collision with drag object 2 Answers
Detect inside Collision 2D 0 Answers
Make EventSystem ignore a collider 0 Answers