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 14, 2012 at 04:01 PM · boatexplodesinking

after shot how to make a boat sink

hey people, i have this question of scripting i cant solve, hope ou can help me!

I am making a game that consists of a naval battle, and when shooting toward a boat, i wanted to make it explode and then sank, someone has an idea how can I do this?

i already have my script to shoot bullets, and a collider but it is no good...

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 ruifernandes01 · Jun 15, 2012 at 02:30 PM 0
Share

Tnx a lot that is a great idea! but i'm still with a problem, i'm not also a big programmer!

I've thought about doing this myself, but the problem is to add a score, it would be fantastic in my game, and I've seen some toturiais to see if I can make score, but so far I've seen toturiais of version 2.9 of unity and it's predictable, the language has evolved and the code is no longer the same! do you know any toturial that can $$anonymous$$ch me how to do this?

Ps: plz someone answer me that, because I'm in a race against time to deliver this project until 22 of this month!

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by 2BitPixel · Jun 14, 2012 at 05:39 PM

I'm not a code Guru so I wont be able to provide you with the code to do this without testing it but If you just need a step in the right direction this is what I would do:

Make a function that handles the boats health and upon collision with the bullet have it subtract an amount from the health total

When the total reaches zero, instantiate a particle system for the explosion at the position of the boat, have an animation that sinks the boat, trigger the animation after the explosion and then destroy the game object to get rid of the boat from the game.

Maybe someone else can post some code but this is how I would handle the boat.

Hope that helps a little.

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

Answer by ruifernandes01 · Jun 15, 2012 at 10:01 AM

Tnx a lot that is a great idea! but i'm still with a problem, i'm not also a big programmer!

I've thought about doing this myself, but the problem is to add a score, it would be fantastic in my game, and I've seen some toturiais to see if I can make score, but so far I've seen toturiais of version 2.9 of unity and it's predictable, the language has evolved and the code is no longer the same! do you know any toturial that can teach me how to do this?

Ps: plz someone answer me that, because I'm in a race against time to deliver this project until 22 of this month!

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

Answer by Sapidus3 · Jun 15, 2012 at 05:31 PM

I wouldn't say that this is the best way to do it, but this should be some easy to understand code. Have this in a script attached to your boat.

 //You will assign these two transforms in the inspector
 //The first will refer to a prefab
 //The second one to a "controller" object in your scene.
 var explosion : Transform;
 var pointMaster : Transform;
 //Call this function when the boats health reach's zero
 function Sink () {
    animation.CrossFade("Sink");//Or whatever your sinking animation is called.
    Destroy(GameObject,timeForBoatToSink);
    //Replace timeForBoatToSink with the time it takes for your animation to play.
    pointMaster.GetComponent(pointController).points+=1;
 }

Then on your pointMaster object you have the following script:

 var points = 0; //This will make it an int.
 //If you want it to be a float, set it equal to 0.0
 //You could also add a part in OnGUI to display the current number of points.
 //And that's all you need.

Finally you will want to create an explosion gameobject. You will give it a particle system that you like, the following script, then assign it to a prefab and that prefab to the above script. This following script will get rid of the explosion gameObjects when they have filled their use.

 var lifeTime = 3.0f;//This is how long it takes your explosion to "play out"
 function Start () {
    Destroy(gameObject,lifeTime); 
 }


There are better ways to do this, but it should work and be easy to understand. Note, I did not test this script, so there might be typos.

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

Answer by ruifernandes01 · Jun 18, 2012 at 08:02 PM

tnx a lot sapidus3, but can u tell me what do u mean with:

pointMaster.GetComponent(pointController).points+=1;

it's that i get an error when i'm compiling it:

Unknown identifier: 'pointController'

Comment
Add comment · Show 4 · 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 Sapidus3 · Jun 19, 2012 at 03:03 AM 0
Share

Sorry I left something out of my description. The second script on the point$$anonymous$$aster object should be called pointController.

Also, just for future reference. You should post responses to or questions about answers as comments on the answer, not as separate answers.

avatar image ruifernandes01 · Jun 19, 2012 at 11:01 AM 0
Share

ok, tnx for that advice! ;) things are working out very well, but the are some thing i still dont understand, like what is the prefab i must attached so the variable in the inspector called "point master"? $$anonymous$$y prefab of the bullet? And one other thing, how can i put the score in my camera? in a way i can see it in the top corner of the screen.

And by the way, you are my rescuer! you have no idea how must you're helping me, so once again, tanks a lot! :)

avatar image Sapidus3 · Jun 20, 2012 at 05:32 PM 0
Share

You need to create a new prefab that will have the point Controller script.

To display the score (which is a completely different issue) you can use the GUI system. Here is an example: http://answers.unity3d.com/questions/34014/live-systemscore-etc.html

avatar image ruifernandes01 · Jun 20, 2012 at 08:38 PM 0
Share

what should be : var explosion?// what prefab? var point$$anonymous$$aster ?// what controler object? what is that?

and this new prefab? what will it do? and where should i place it?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Prefabs & scripts 1 Answer

Realistic boat physics? 0 Answers

Controllable boat script 0 Answers

Wants to rowing 0 Answers

Row Boat script 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