Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Assets Water 2D Tool - GPU based ripple water, realistic buoyancy, water flow & animation

Discussion in 'Works In Progress' started by Nicrom, Feb 23, 2015.

  1. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    One thing you could do is to increase the density of the water.
     
  2. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    95
    will test, thanks
     
    Nicrom likes this.
  3. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    95
    and i again, hi!

    The next question I have a waterfall
    I want to go to a place where the water drops randomly create the effect of hitting the water
    I made out the script and realized that it's very original works
    in this method of variable tempObj2D GenerateWaterWaves deleted and new objects created by a blow to the heights

    where the method of processing incoming blows on the water? and it is not present (((

    you next release to make a separate method for this (global position / radius / force)

    Code (CSharp):
    1. public void collision_input(Vector3 __position,float __radius,float __force) {
    2.  
    3.             float __distance=Mathf.Abs(leftHandleGlobalPos.x-__position.x);
    4.  
    5.             float __minX =Mathf.Max(0,__distance-__radius);
    6.             float __maxX =Mathf.Min(Vector3.Distance(water2D.handlesPosition[3], water2D.handlesPosition[2]),__distance+__radius);
    7.  
    8.             int __minIndex = (int)Mathf.Floor(__minX/(1f/water2D.segmentsPerUnit));
    9.             int __maxIndex = (int)Mathf.Floor(__maxX/(1f/water2D.segmentsPerUnit));
    10.  
    11.             for (int i = __minIndex; i<__maxIndex; i++) {
    12.  
    13.                 velocities[i]+=__force;
    14.             }
    15.         }
     
    Last edited: Dec 28, 2015
  4. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    From what I understand, you ask if I could add this method in the next update. Is that right? If so, no problem I will add it.
     
  5. ask80me

    ask80me

    Joined:
    Sep 17, 2015
    Posts:
    43
    Hello. Asset conflict Simply SVG.
     
  6. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Hello. What exactly causes the conflict? Water 2D Tool has its own namespace so there should not be any conflicts normally. Is this the Asset That causes the conflict Simple SVG?
     
    Last edited: Jan 15, 2016
  7. ask80me

    ask80me

    Joined:
    Sep 17, 2015
    Posts:
    43
    Variables Clipper (Poly)
     
  8. ask80me

    ask80me

    Joined:
    Sep 17, 2015
    Posts:
    43
    Assets/Water2D_Tool/Scripts/ClipperLibrary/Clipper.cs(73,19): error CS0101: The namespace `ClipperLib' already contains a definition for `DoublePoint'
    25 Error :)
     
  9. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    I think I know what the problem is. Water2D Tool as well as Simple SVG use Clipper library. One way to fix this is to change the namespace of the clipper library script that Water 2D Tool uses or the one that Simple SVG uses, I would recommend to change the one that Water 2D Tool uses as its not hard to do. Just open Clipper script (Water2D_Tool/Scripts/ClipperLibrary) and change it's namespace to something like ClipperLib_Water2D. After that open Water2D_Simulation script and replace ClipperLib with ClipperLib_Water2D in the first lines of code.
     
    Last edited: Jan 15, 2016
  10. ask80me

    ask80me

    Joined:
    Sep 17, 2015
    Posts:
    43
    Thank you. Your method of correction is clear. But it would be without the intervention of downloading assets

    Versatility is needed. When waiting for the update?
     
  11. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    In think I'll release a small update soon with the namespace change.
     
  12. ask80me

    ask80me

    Joined:
    Sep 17, 2015
    Posts:
    43
    And really there to make the water of any form?
     
  13. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    You mean have a water that is not a rectangle, but more like a polygon that can be reshaped ?. Well that is something I plan to add eventually, but cant say for sure if this feature will be included in the next update.
     
  14. ask80me

    ask80me

    Joined:
    Sep 17, 2015
    Posts:
    43
    That's what I mean. Thank you for your asset.
    We are looking forward to the update.
     
  15. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    582
    Hey Nicrom,

    I'm again considering replacing my own water system with yours. While doing so, I noticed I get an error when adding the Water2D_Simulation component. This is happening in the 5.4 beta.

    The error is:

    UnityException: LoadAssetAtPath is not allowed to be called from a MonoBehaviour constructor, call it in Awake or Start instead. Called from script 'Water2D_ToolEditor' on game object ''.
    See "Script Serialization" page in the Unity Manual for further details.
    Water2DTool.Water2D_ToolEditor.GetGizmo (System.String aFileName) (at Assets/Water2D_Tool/Editor/Water2D_ToolEditor.cs:377)
    Water2DTool.Water2D_ToolEditor..ctor ()

    It's this line, in Water2D_ToolEditor, that actually causes the issue:

    Code (CSharp):
    1. private Texture2D texDot = GetGizmo("water2D_circle.png");
    If I move the GetGizmo(...) call inside the OnEnable() method, all is good.

    [
    Code (CSharp):
    1.  
    2.         private Texture2D texDot;
    3.         private List<int> selectedPoints = new List<int>();
    4.         private bool prevChanged = false;
    5.         private bool showVisuals = true;
    6.         private bool showCollider = true;
    7.         private static float pathScale = 1f;
    8.  
    9.         void OnEnable()
    10.         {
    11.             selectedPoints.Clear();
    12.             Water2D_Tool water2D_Tool = (Water2D_Tool)target;
    13.             if (water2D_Tool.GetComponent<MeshFilter>().sharedMesh == null)
    14.                 water2D_Tool.RecreateWaterMesh();
    15.  
    16.             texDot = GetGizmo("water2D_circle.png");
    17.         }
    18.  
    -Jeff
     
    Nicrom likes this.
  16. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Hi. Thanks for pointing this out, Jeff.
     
  17. Vaulcul

    Vaulcul

    Joined:
    Apr 3, 2016
    Posts:
    32
    Hi,

    First, I think what you've done is great! It really adds a lot to water in 2D.

    I'm running into a problem where if I import your Water2D Tool asset with Platformer Pro (https://www.assetstore.unity3d.com/en/#!/content/43863) the water flow and buoyancy breaks... at least in the 1.2 examples... and my game project (oddly it still seems to work in the 1.1 examples). Even if I delete all assets and re-import just the water 2D asset the water flow and buoyancy stay broken (I basically have to open a new project to get Water 2D to work again).

    I have not seen any errors thrown... Otherwise I'd include them.

    Edit - Here's a video of the issue (sorry no mic sound) Platformer Pro has been imported and deleted on the project on the left:
    onedrive.live.com/redir?resid=2C735F0C4992961C!10283&authkey=!ACRzypx5rlqxGZQ&ithint=file%2cmp4

    FYI - I've also contacted the Platformer Pro dev on the issue.
     
    Last edited: Apr 3, 2016
  18. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Hi. Thanks.

    What version of Unity are you using.?
    When you create a new water object, is this bug still present.?
     
  19. Vaulcul

    Vaulcul

    Joined:
    Apr 3, 2016
    Posts:
    32
    I was using Unity 5.3.2f... this is where I started to see the issue... Then I updated to 5.3.4f, knowing that it's mostly stability fixes... but this didn't do anything either.

    Interestingly, creating a new water object caused the water physics to work again.

    This is great! thank you for pointing out how to fix this.

    EDIT - So, this fixed the project that had Platformer Pro in it and then removed... but didn't work in my main game file that still had Platformer Pro in it.

    The Dev from Platformer Pro suggested that I try removing the 2D Physics Asset that Platformer Pro installs. Doing this fixed the water in my project... Not sure what kind of issues this created though.

    Still working with the Platformer Pro dev. I'll let you know if something new comes up with the issue.

    EDIT 2 - I think I've got this figured out mostly (everything seems to be working at the moment)... The Platformer Pro dev felt that if there needed to be anything else worked out between your two assets that you should contact him (support@jnamobile.com). He seems pretty open to making sure there is max compatibility with assets like yours.

    Thanks again for your response.
     
    Last edited: Apr 6, 2016
  20. alexsan75

    alexsan75

    Joined:
    Feb 6, 2012
    Posts:
    95

    Very cool Asset must say! :) Bought it, liked it, trying to implement into my game, but.. I have some problems with 2D water when using TNT/Bombs in the water. I have, let's say, many objects/2D sprites (10-30) which can be destroyed.
    I'm using 'TNT explosions' based on Unity 2D tuts - with 2D Point Effector. It works fine if I only use one explosion/bomb, but I get rather unstable behavior when placing two or more such 'bombs' ?

    I'm getting this msg "The object of type 'BoxCollider2D' has been destroyed but you are still trying to access it", the one you warned about. I'm using suggested First Option, but it still doesn't quite work if I have multiple explosions.. especially if those are close in proximity or happens within short time interval.
    I tried many different modifications, but I cannot "catch" which 2D Colliders get destroyed ?

    Any thoughts or suggestions on how to solve this problem? Appreciate it, thanks!
     
  21. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Hi. Thanks for buying Water 2D Tool.

    Did you try to use the second option for destroying objects in the water.?
     
  22. alexsan75

    alexsan75

    Joined:
    Feb 6, 2012
    Posts:
    95
    Yes, I tried it now, but looks like problem might be elsewhere.

    Q: does 2D Water caching objects somehow? kinda weird, I get immediately Error msg if I do one of following:
    -I duplicate (within Scene) one of the objects, any object, and run Scene,
    -add any new prefab from Resources to the Scene and run,
    -just run/stop the same Scene few times: mostly works, but I get Error time to time
    Can't really figure out why is it so unstable?
     
  23. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    A reference to every object that enters the water's Box Collider is stored in a list by the Water2D_Simulation script. If you destroy an object, but the reference to it is not removed from that list you get the error "The object of type 'BoxCollider2D' has been destroyed but you are still trying to access it".

    Do you still get the above error?
    What other errors do you get?
    What do you mean by unstable?
     
  24. alexsan75

    alexsan75

    Joined:
    Feb 6, 2012
    Posts:
    95
    I started conversation instead, if that's ok. Please, check. I really need to solve my problem :( , fighting this issue for a few days already, without much success..
     
  25. Mijago

    Mijago

    Joined:
    Mar 27, 2016
    Posts:
    11
  26. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    I don't think so. In order for the player to interact with the water it must be dynamic (not kinematic). I tried before to make the Water 2D Tool compatible with ray cast based character controllers, but without success.

    The only solution I can see is to change to a physics based character controller. Have you heard of Acrocatic character controller. It's free and has many features. Once it was a payed asset, but the developers moved to a new project so they made it free.
     
  27. Mijago

    Mijago

    Joined:
    Mar 27, 2016
    Posts:
    11
    Okay, thank you for your quick response!
    (Not as Uplay support, they needed 4 months and 3 supporters to finish my simple ticket)

    I had the same problem as alexan75 and none of your solutions worked :c
    But I fixed it myself and I want to share my solution.

    I added this function to the Water2D_Simulation.cs
    Code (CSharp):
    1.         private bool CheckIndex(int cIndex, bool a2DCollider)
    2.         {
    3.             if (a2DCollider)
    4.             {
    5.                 if (floatingObjects2D.Count <= cIndex)
    6.                     return true;
    7.                 if (floatingObjects2D[cIndex] == null)
    8.                 {
    9.                     floatingObjects2D.RemoveAt(cIndex);
    10.                     return true;
    11.                 }
    12.             }
    13.             else
    14.             {
    15.                 if (floatingObjects3D.Count <= cIndex)
    16.                     return true;
    17.                 if (floatingObjects3D[cIndex] == null)
    18.                 {
    19.                     floatingObjects3D.RemoveAt(cIndex);
    20.                     return true;
    21.                 }
    22.             }
    23.            
    After that, I added the following code to the top of ApplyWaterDisplacement, GenerateWaterWaves and ApplyPhysicsBasedBuoyantForce:
    Code (CSharp):
    1.             if (CheckIndex(cIndex, a2DCollider))
    2.                 return;

    Now everything just works like a charm!
     
    Last edited: May 29, 2016
    Nicrom likes this.
  28. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Water 2D Tool version 1.3 is live now on Unity Asset Store.

    This version contains 2 new small features and a fix for an error that was generated when importing the plugin in Unity 5.4.
    • The size of the water (height, width) can be set in the inspector. This will be useful if you want the water to have a specific size.
    • If you want to use a custom buoyancy or the Unity buoyancy you can disable the Water 2D Tool buoyancy from the inspector. This will only effect the Water 2D Tool buoyancy. The spring simulation will work as before.
     
    Too-Nerd-To-Die likes this.
  29. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    This tool looks wonderful; but do you know if/when you'd be able to add a sort of Polygonal shape tool? Much of my game's current needs require various heights and water surfaces, unfortunately!

    For example, I'd commonly run into situations such as this, where a single rectangle wouldn't work: http://i.imgur.com/HQSRKXS.png
     
  30. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    At the moment this is not possible. This something I want to add too. I hope to add it in a future update, but cant say for sure when that will be.
     
  31. MaceB

    MaceB

    Joined:
    Jun 26, 2016
    Posts:
    5
    Hello,

    Today I purchased your Water 2D Tool from the Unity Asset Store and it’s fantastic. I ran into a problem which I’ve been trying to fix all day but couldn’t manage to solve. When my 3D objects are dropped into the water, no waves are created. The object begins to float like it’s supposed to be when it is dropped into the water no waves are created. I looked at the water you used in your sample 2.5D scene and copied all of the elements in the inspector to my scene and also looked at the player object but it still isn’t creating waves. Rigidbodies and Colliders are attached to the objects in my scene.

    Thanks in advance.
     
  32. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Hi.

    If you are using 3D colliders, this is probability happening because your objects do not interact with the blue spheres. Use the field Box Collider Z Offset to change the position of the blue spheres.
     
  33. Nishimaster

    Nishimaster

    Joined:
    Jul 22, 2016
    Posts:
    5
    Hey there, i'm greatly enjoying your asset - running into a couple of issues at the moment though.

    I'm not getting splash sounds/particles or waves come out of my water when the player lands in it, except for if I land in the very far left corner of the water.

    http://puu.sh/qbBdZ/65cd1f4887.png here are the settings for my body of water. It is 3 units high and 6 units wide.
    My player is roughly one unit square in size, and has a mass/gravity of 1 (and has a rigidbody2d and 2d colliders on it).

    How would I go about getting this to provide a decent amount of waves come out from a player landing at any point in this body of water?

    I'm also interested in getting the water to drain on a bool flag - changing the water height or current water area to zero via a script doesn't seem to have any effect - how would I go about getting this effect?

    I also get an error when destroying an object that's in the water. "MissingReferenceException: The object of type 'BoxCollider2D' has been destroyed but you are still trying to access it." - is there a way around this?
     
    Last edited: Jul 23, 2016
  34. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Hi. Thanks for buying Water 2D Tool. Sorry for the late reply, different time zone.

    The generation of sounds/particles or waves does not depend on the position of the object in the water on the X axis, so this is quite an unusual behavior. Could you make a GIF or a small video of this and show it to me?

    The size of the waves depends on size of the object and its velocity when falling in the water. In the Springs group of settings the is a field called "Collision Velocity". Increase the value of this field to make the waves generated by small objects more pronounced. Set its value to something like 0.02 or 0.03.

    Water 2D Tool comes with the ability to animate the water, so what you want to achieve is quite simple to do. Have you watched the video tutorials on how to animate the water


    This is happening because Water 2D Tool kips an reference to all the objects that are in the water, in a list. When you destroy an object in the water the reference to it is not removed from this internal list so you get an "MissingReferenceException" error. On the second page of this forum thread, post number 73, I have presented 2 methods on how this problem can be fixed.
     
    Too-Nerd-To-Die likes this.
  35. Nishimaster

    Nishimaster

    Joined:
    Jul 22, 2016
    Posts:
    5
    Apologies for not reading through the thread, and thank you for the post number for sorting the destroying objects issue.

    http://puu.sh/qdI3B/345c543b02.gif - here is a gif of the splashing / waves. Sorry for the low framerate, but you can see the issue clearly enough.

    I had watched the animation video - as far as I am aware the animator object is just setting the CurrentWaterArea variable. Is it not possible to just do this via script, for example

    Code (CSharp):
    1. GetComponent<Water2DTool.Water2D_Tool>().curentWaterArea = 0;
    2.  
    seeing as though it is effectively doing the same thing as the animator? I have got Animate Water Area set to true.
     
  36. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Try to increase the value of the field "Segments To Units". In order to generate waves/Particle effects and sound effects the distance between 2 water line vertices must not be bigger than the bounding box of the object collider.

    If you want to use the second method of animation where you add an Animator to the water object and animate the water area, you have to animate the variable "Default Water Area Offset" that can be found in the Water2D_Simulation script. On a second note, you can use a script to change the value of the field "defaultWaterAreaOffset" if you want. just don't forget to set the field "Animate Water Area" to true, in the Animation group in the water object Inspector.

    The field "curentWaterArea" from the Water2D_Tool is not used in any calculations. Changing it will not effect the water in any way.
     
  37. Nishimaster

    Nishimaster

    Joined:
    Jul 22, 2016
    Posts:
    5
    Excellent, my draining script now works perfectly, thank you for your fantastic assistance!

    Changing the segments to units seemed to have a negligible effect on the lack of splashing/waves on the right hand side of the water body though, do you have any other suggestions?
     
  38. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    It's a little hard to make more suggestions without looking at the scene of your game. Could you make a copy of your project, remove anything that you don't want other people to see, create a scene with the problem and send the unity project to my email? johnq002@gmail.com
     
    Too-Nerd-To-Die likes this.
  39. Nishimaster

    Nishimaster

    Joined:
    Jul 22, 2016
    Posts:
    5
    I sent you an email, I have to say your support is top notch - I might have to consider purchasing your foliage tool aswell! You're doing the community a huge favour with your work - and i'm sure other people appreciate it as much as I do.
     
    Nicrom and Too-Nerd-To-Die like this.
  40. Roberty

    Roberty

    Joined:
    Jun 11, 2016
    Posts:
    3
    Heya, I am considering getting your asset but have a few questions beforehand:

    1. Does the Water area always have to be a cube?
    2. Can I color in the whole water area in a flat color (Silly question, as I can probably just assign a material.)
    3. What happens if I rotate the water area? Does it stick with its "local" gravity or does it move according to the rotation?
    4. Piggybacking off #3 - can I create some artificial waves just in the moment of rotation for a more realistic look?
    5. Can I assign parent object, and can a parent object contain multiple Water objects?

    Main Idea is to have several water areas that are centered around a point and rotated properly, and then rotating them along that point in the middle like a clockwork.
     
  41. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    Hi. sorry for the late reply, different time zone.
    1. Yes.
    2. Yes. You can change the water texture too.
    3. I assume you want to rotate the water around the Z axis. It depends on the angle of rotation. The buoyant force expects the water line to have a constant angle, so if you rote the water object you may have objects floating in the air in some parts of the water. There are other things that will not work well when you rotate the water objects, like water animation and the handles. You could get away with a small rotation below 10 degrees, but above that you will get visible problems. Making the object a child and rotating the parent will result in the same problems.
    4. Living the rotation aside, at the moment the waves can be generated by 2 methods: by objects falling in the water or by enabling surface waves option in the water object inspector (this are sine waves or random small waves).
    5. Making the water object a child of another object will not break its functions as long as the parent is not scaled or rotated.
     
  42. Roberty

    Roberty

    Joined:
    Jun 11, 2016
    Posts:
    3

    1+2: Would I be able to simply write a vertex shader that puts together all the vertices on the bottom row to get a triangle shape?
    3: Only when the water is in an upright "correct" position I want to drop items into it. And the items would be deleted in an instant. It's just about the wave motion that derives from an object dropping in.

    Do you think you could make a smal gif showcasing a water area with waves as you are rotating it? I think that would greatly help determine if your asset is what I look for :)

    Thanks for the answers!
     
  43. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    I don't think it wold be impossible, but it will not work well. One problem is that the UV coordinates of the bottom vertices would have to be recalculated.

    Here are the waves when the water object is not rotated.



    And here is when it is rotated.



    As you can see the waves are not the same and the box does not even generate a wave. Without some changes to the code It will not work well.
     
  44. Roberty

    Roberty

    Joined:
    Jun 11, 2016
    Posts:
    3
    Thanks. Could I request one last gif of you rotating the object after an object was dropped into it, to see how the waves perform during rotation?

    While it would have its limits in the way I plan to use it, I think it will do the job that I want it to do well enough. :)
    Thanks for taking the time, btw.
     
  45. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    No problem.

    Here the water object is animated using an Animator.

     
    Last edited: Aug 14, 2016
  46. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    60
    Hey! Can I use this asset for infinite water runner? Can I change waves values in runtime? Can I randomly generate really big waves from left or right sides?
    Thank you!
     
  47. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    I have not tried to use Water 2D in an infinite runner, but I think it should be possible. You could animate the left and right sides of the water so that they follow the player. This way you could get a relatively constant water mesh size.

    By default the velocities of the surface vertices are stored in a private list called "velocities". You can just make it public and access it from other scripts. Changing the values of this list at run time is not a problem.

    In the current version it's kinda possible to randomly generate waves from the left or right side. Water 2D has a feature called Control Point, where you change the velocity of a single vertex and leave the rest to the spring simulation to generate the wave. It's not very flexible and I'm not sure if this can be used the way you want it. A GIF that shoes the Control Point feature can be found in post number 65.
     
  48. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    60
    Tell me please, how can I generate wave by tap?
     
  49. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    340
    One way I can think of, is to change the velocity of the vertex that is closest on the X axis to the tap point. You'll need to find the global position of the point where you taped the screen, then find the closest water line vertex to this tap point. Changing the velocity of a single water line vertex will not produce a very realistic wave so you'll have to change the velocities of at list 2 or 3 neighbours (left and right) of the water line vertex that is closest to the tap point on the X axis.

    To find the closest water line vertex to the tap point on the X axis use the following code.
    Code (CSharp):
    1. // The distance from the left edge of the water to the tap point on the X axis.
    2. float distance = leftHandleGlobalPos.x - tapPoint.x;
    3.          
    4. // The current water width.
    5. float waterWidth = Mathf.Abs(water2D.handlesPosition[3].x - water2D.handlesPosition[2].x);
    6.  
    7. if (distance < 0)
    8.     distance = 0;
    9. if (distance > waterWidth)
    10.     distance = waterWidth;
    11.  
    12. // The index of the surface vertex that is closest to the tap point.
    13. int vertIndex = (int)Mathf.Floor(distance / (1f / water2D.segmentsPerUnit));
    14.  
    15. // We make sure that we don't get out of bounds indexes.
    16. if (vertIndex > surfaceVertsCount - 1)
    17.     vertIndex = surfaceVertsCount - 1;
    18. if (vertIndex < 0)
    19.     vertIndex = 0;
     
  50. chronowake

    chronowake

    Joined:
    Sep 5, 2016
    Posts:
    2
    I tried using this and it says that not every code path returns a value. I don't see a problem, but my coding experience is limited. Any advice?
     
unityunity