Hello all, I'm just beginning to learn unity scripting. I'm trying to implement them as I learn some very basic functions along the way.
This link from unity taught me the basics of OnCollisionEnter() - which, as far as I understand, executes some piece of code whenever it detects collisions with a gameobject (there they named it as prop_powerCube).
Now I tried to implement it in C# and I had something like:
using UnityEngine;
using System.Collections;
public class Mine : MonoBehaviour {
// Use this for initialization
void Start () {
int health=10;
}
// Update is called once per frame
void Update () {
//public class DestroyCubes : MonoBehaviour
{
OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "Sphere")
{
//Destroy(col.gameObject);
health-=5;
}
}
}
Debug.Log("Health=", health);
}
In short, it would detect collisions with 'Sphere' and decrease the health of the player by 5. The problem I understand is with "col".
It is a variable of type Collison. But how do I explicitly declare it in this case?
MY AIM: WHENEVER MY PLAYER COLLIDES WITH A SPHERE, HIS HEALTH DECREASES BY 5 UNITS.
Please guide me where am I missing it...