- Home /
Duplicate Object, by dragging? (SporeCreatureCreator Like)
Ok so this question, it's weird to explain but i will do my best:
I am doing some kind of "Spore Creature Creator", and I have the "Spine" of the creature (Simple cylinders one behind the other), at the moment each cylinder has a drag and drop script and they are conected by joints so i can move and pose them freely with my mouse:)
The next thing I have is an "arrow" object (triangle in top of a square) at the two ends of the spine.
Here is the question: How can I tell unity, that when I drag this arrow away from the spine end, a clone of this spine end appears next to the previous one (like adding an extra vertebrae), and when i drag it in the oposite direction, cylinders start to disapear.
I made this drawing to explain:
An here is the script I use to drag the cylinders freely in the scene, it's useful:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CapsuleCollider))]
public class CyllinderDrag : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint)+offset;
transform.position = curPosition;
}
}
This script could help, but it spawns the copied object at start. I think that for my idea maybe if each cylinder has an empty object attached to it. The only thing is i don't know how i can make that the copied cylinder spawns in the empy object with the same position the previous cylinder has. And i don't know also how to make it work by dragging it:/. Please help, I think i'm close....Here is the script I found:
// Create an empty object in scene
// Attach this script to any object in scene
// See: emptyObject.transform.position, emptyObject.transform.rotation
// Location and rotation are params 2 & 3 of Instantiate()
var emptyObject : Transform; // Drag empty object here
var drop = false;
var clone : Transform; // Drag your clone obj here
function Start() {
drop = true;
}
function Update ()
{
if (drop)
{
Instantiate (clone, emptyObject.transform.position, emptyObject.transform.rotation);
drop = false;
}
}
Your answer
Follow this Question
Related Questions
Drag and Drop Using Mouse (2D) 1 Answer
How to destroy gun bullet clone? 1 Answer
Drag and Drop Inside Editor 0 Answers
How do I properly destroy an instance of a prefab from within its own script? 1 Answer
Clones not being Destroyed 1 Answer