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 ruifernandes01 · Jun 23, 2012 at 11:18 AM · animationprefabsdestroy objectboat

How to shoot prefab, and then on colliding destroy a gameobject?

Hey! I'm making a battleship game and so far, it been good but now i want to add a script that when i'm shooting my prefab(my bullet), in colliding with a game object(rival boat) an animation plays, and then destroy.Gameobject. i'm not some scripting guru, and now i'm stuk! can anyone help me with this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Hybris · Jun 23, 2012 at 01:24 PM

Well, I will give you some tips to start. To begin it's not

 destroy.Gameobject

it's

 Destroy(GameObject);

You already know how to shoot right? If not you can use the shoot function I gave you in the question of the turret AI(yes that was me)

Well to check if the bullet hit something do this:

 function OnCollisionEnter(hit : Collision){
     if(hit.transform.tag == "rivalboat"){//this checks if the object you hit is a
         //transform tagged "rivalboat"
 
         yield WaitForSeconds(anim.length);
         Destroy(hit.GameObject);
     }
 }

This script would go to the bullet. you need to define anim as an animation for this to work. cuz I think you meant that it plays an animation if it's dead or hit and then it destroys.

Little misunderstanding, If you want to use the explosion prefab, just instantiate it:

 var explosion : Rigidbody;//Need to apply a rigidbody 2 the prefab if you use this
 var explosionSpawn : Transform

and then:

 Instantiate(explosion, explosionSpawn.position, explosionSpawn.rotation);

Good Luck -Hybris

PS: Dont forget to give an upvote or mark it as right answer(the green button beneath the downvote)so it gets removed from the unsolved list and the users who answered it don't get their karma.

Comment
Add comment · Show 11 · 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 ruifernandes01 · Jun 23, 2012 at 04:26 PM 0
Share

noted! :) And I was still waiting for an anwser of you in that matter, when ever u want, just need to pass here: http://answers.unity3d.com/questions/256809/turret-ai-question.html about this one, i still dnt have my animation on it, i wanted to place it in the middle of this script, u thinks it is too complicated? I already have my prefab of the explosion(the animation, i will play), just wanted to open a new var animation : transform; so i can change it whenever i want, but i dnt know how to "play" this animation..

avatar image Hybris · Jun 23, 2012 at 07:25 PM 0
Share

I already answered that one, the one you asked with the screenshot right? Did that, and I updated the code, and threw a comment in! if you still have a problem contact me(I check my recent answers alot)! and about the animation, I will edit my answer!! quick tip

A transform is a gameobject in a scene with a vector3(x, y, z), the vector3 is the position in the scene. A animation is not an object so it's impossible to assign an animation to a transform, animation are complicated I'm gonna update my answer now!

Haha, I even found an error in my own script

If you have any questions, or need anything contact me at: thomasoosterbeek@hotmail.com

avatar image ruifernandes01 · Jun 23, 2012 at 07:40 PM 0
Share

But my animation is in a prefab! from the explosion framework of unity assets, i was planing on using one of those, can't it be adapted to that?

avatar image Hybris · Jun 23, 2012 at 07:42 PM 0
Share

Oh, like the explosion prefab! That's not an animation! Those are particles! I will edit again! I will keep the part about animations for others!

avatar image ruifernandes01 · Jun 23, 2012 at 08:24 PM 0
Share

ok! just instaling messenger, to speak to u, i prefer skype :P anyways, so now u have created two variables, i suspect that the first one should be for my explosion prefab with an rigid body attached to him, but wath about the second one?

Show more comments
avatar image
0

Answer by generic cereal · Feb 15, 2013 at 01:02 AM

Do you think you could post what this entire script would look like? Sorry I'm very new to scripting... are there any vars? How do you know if your GameObject is a transform?

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

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Scripting BUG: target becomes bigger when getting nearer 1 Answer

Can the animation editor create local rotational data? 3 Answers

fireball animation 2 Answers

Is it possible to manipulate Mecanim state machine / blend trees from scripting? 0 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