Hello, I’m a student of VIT BHOPAL
Name : Ansh Parashar
Reg . No. : 20BCG10106
So I’m going to show how to make an object(Boat) float on water .
So first we have to add water in our scene ,like this
You can get this on asset store if u wanted (i.e, LowPoly Water)
Now add a Floating object u wanted …..
I have add a boat like this

Now ,we have to Create a script for the floating object(BOAT)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class floatobject : MonoBehaviour
{
public float waterlevel = 0.0f;
public float floatthreshold = 2.0f;
public float waterdensity = 0.1250f;
public float downforce = 4.0f;
float forceFactor;
Vector3 floatForce;
void FixedUpdate()
{
forceFactor = 1.0f - ((transform.position.y - waterlevel) / floatthreshold);
if(forceFactor > 0.0f)
{
floatForce = -Physics.gravity * GetComponent<Rigidbody>().mass * (forceFactor - GetComponent<Rigidbody>().velocity.y * waterdensity);
floatForce += new Vector3(0.0f, -downforce*GetComponent<Rigidbody> ().mass , 0.0f);
GetComponent<Rigidbody>().AddForceAtPosition(floatForce, transform.position);
}
}
So this Script will make your object float on water and this is it ……
Further u can add script to the object to make it move …….
Here are some references and source where you can download and find the material :
https://answers.unity.com/questions/879712/making-an-object-float-in-water.html
https://docs.unity3d.com/560/Documentation/Manual/HOWTO-Water.html
THANK YOU.