Water Question

I was wondering how could I add a script to allow when you go underwater to deduct 5 health every 10 seconds you are under. How could I go about doing that?

I shall start from the beginning to help explain the process you need to follow.

I’ll be using video links to help you see the concepts working.

Using Triggers and OnTriggerEnter :

  • Beginner B13 - Trigger Collision Detection

http://www.unity3dstudent.com/2010/07/beginner-b13-trigger-collision-detection/

Note how setting the trigger to True (tick), and setting the Mesh Renderer to False (Untick), you can create a ‘zone’ that you can place where you want the trigger to occur.

  • Also , and probably most Importantly , read the Unity Scripting Reference on the commands you want to use :

http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html

  • Here is the link to other video’s in the beginner set by Unity3Dstudent :

http://www.unity3dstudent.com/category/modules/beginner/

If you watch these and are still having trouble, I am happy to help you edit your scripts to get the effect you are after.

Please ignore the -1 vote to you. Some people find it hard to understand we were all noobs once. Keep asking questions (as long as they’re reasonable) and you’ll find nearly all of the other members of this 'site are friendly and helpful.

In regard to asking questions, have a quick look at these links :

the FAQ appears at the top of the page : Frequently Asked Questions - Unity Answers

also : How do I ask a good Question? - Questions & Answers - Unity Discussions

If your water is always at the same Y you could have like : When my object position is under Y you launch a counter that will decrease your life by 5.

Else, You need to put triggers and check ontriggerenter.