Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by fernandovt · Jul 02, 2014 at 04:29 PM · destroydragclonedrop

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:

alt text

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;
         
     }
     
 }


spine creator.jpg (78.5 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fernandovt · Jul 02, 2014 at 05:43 PM 0
Share

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;
  
     }
 }

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges