I want to make it so that when i jump into water it will create a splash effect. I know that I need to do an “OnCollionEnter” command but I can’t get the script right. this is what i have.
OnCollisionEnter
function Update (
CreateGameObject (target) {
}
I know there is a error in here, I am not very good at scripting. Please help!
OnCollisionEnter needs to be implemented the same way as ‘Start’ and ‘Update’ are. Like so-
function OnCollisionEnter(var collision : Collision)
{
CreateGameObject(target);
}
Of course, this assumes that you have already defined a CreateGameObject function, which would be something like
function CreateGameObject(var target : Transform)
{
Instantiate(splashPrefab, target.position, target.rotation);
}
On the other hand, that wouldn’t be a very good way of doing splashes- you would be better served to use ‘OnTrigger’ and make the water a trigger volume, not a normal collider, otherwise it would be solid.
function OnTrigger(var hit : Collider)
{
Instantiate(splashPrefab, transform.position, Quaternion.identity);
}
You should look up some basic scripting tutorials, and once you’ve done those, have a good read through the Unity Scripting Reference which ships with your copy of unity (just go to the ‘help’ menu) to get a feel for the capabilities and limitations of the systems available to you.