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
1
Question by Sickgamerstyle · Jan 26, 2013 at 01:47 AM · gamerpg

How to destroy a certain object with another certain object?

Hello unity! I'm a 10 year old developer currently working on an RPG. What I want to know is how do I make a pickaxe destroy rock. So I have a boulder in-front of my town and firstly I need to know how to destroy it on mouse click. Secondly I need to know how to destroy it with pickaxe only. Thanks!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Jan 26, 2013 at 02:02 AM

Welcome to Unity! Well, destructible objects usually are completely fake (as almost everything in the game world): you may have several models, one for each destruction stage, and replace the rock model as the pickaxe destroys it; another possibility is to create models of the broken rock pieces, and join them together to represent the healthy rock - throw them out one by one after each pickaxe hit (or mouse click).
In both cases, however, the main work is to create the models, which must be done in some 3D editor like Blender, 3DMax, Maya etc.

EDITED: This is an example of the first technique, where there are different models for each level of destruction. You must make a model of the healthy rock, then duplicate this model and edit the copy to show some destruction, then duplicate it and add more destruction, and so on. Save all models and import them to Unity. Create an empty game object (Rock), drag the healty model to the scene, child it to the Rock and zero its position and rotation. Drag another model to the scene, child it to the Rock and adjust its position, then repeat this for all models. Drag the script below to the Rock, then in the Inspector assign the models to the array Models - the first one must be the healthy rock. The script has prevision for a pickaxe sound: if you want to use it, add an AudioSource component to the Rock. Finally, drag the Rock to the Project view to make it a prefab.

 using UnityEngine;
 using System.Collections;
 
 public class DestructibleObject : MonoBehaviour {
 
     public GameObject[] models; // drag the models orderly here
     public AudioClip pickaxeSound; // add a sound, if you want
     public float health = 100;
     public float damage = 8;
     
     private float curHealth = 0;
     
     void SelModel(int num){
         // disable all models first...
         foreach (GameObject model in models){
             model.renderer.enabled = false;
         }
         // then enable only the selected model 
         models[num].renderer.enabled = true;
     }
     
     void Update(){
         if (health != curHealth){ // if health changed...
             curHealth = health; // update curHealth...
             // calculate model index: 0 is 100% healthy
             int index = (int)(models.Length * (1 - (health / 100f)));
             SelModel(index);
         }
     }
 
     // Click the rock to damage it:
     void OnMouseDown(){
         if (pickaxeSound){ // if pickaxe sound defined, play it
             audio.PlayOneShot(pickaxeSound);
         }
         health -= damage; // apply damage
         if (health <= 0){ // if health ended, destroy rock
             Destroy(gameObject);
         } 
     }
     
 }
Comment
Add comment · Show 1 · Share
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 Sickgamerstyle · Jan 26, 2013 at 03:20 PM 0
Share

Thank you! but may I have a script or something as I am learning C# so I would lovesome help. Thank you!

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

10 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

Related Questions

How To Make A Simple MMO? 3 Answers

A node in a childnode? 1 Answer

Pathfinding for RPG games 2 Answers

FPS KIT VERSION 2.0 0 Answers

Unity: C#: Eyes look at mouse: HELP!! 3 Answers


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