My character needs to interact with items. In this case, he needs to be able to cut down trees. Most of the code for it i have worked out, the bit i am stuck on is how to apply damage to an object when clicked on.
So far i have this:
function Update () {
var hit : RaycastHit;
if (Input.GetButtonDown("Fire1")) {
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit)) {
Debug.Log(hit.collider.tag);
if(hit.collider.tag == "Tree") {
Debug.Log ("tree");
SendMessage ("ApplyDamage", 5.0);
}
}
}
}
with this attached to the tree object
function ApplyDamage (damage : float) {
print (damage);
}
However, although it can detect that the item is a tree on a click, it throws up the error:
SendMessage ApplyDamage has no receiver!
UnityEngine.Component:SendMessage(String, Object)
mousefire:Update() (at Assets/Scripts/Gameplay/mousefire.js:16)
I will be missing something here, still finding my way around code
Any help will be welcome.
i get this error: Assets/Scripts/Gameplay/mousefire.js(16,37): BCE0019: 'gameObject' is not a member of 'UnityEngine.RaycastHit'.
– darkironphoenixSorry, updated the answer above.
– whydoidoitPerfect, thanks for the speedy reply. You must just be in it for the hugs from random people. :)
– darkironphoenixMaybe that's it!
– whydoidoit