|
Post by jrackley on Mar 12, 2017 19:06:59 GMT
Sorry for the newbie question here but I am having a hell of a time trying to figure out how to get my animal to apply damage to the character. I see in the code that it says to use the TakeDamage method to apply damage, however I can not get this to work at all. Here is an example of what I am trying.
I know I am not the best coder so any help would be appreciated, I just need the correct method to call and be able to apply damage to the character when it is hit by the animal.
And I cannot use the the vObjectDamage for this before it is mentioned(lol).
thank you in advance for any help and sorry for the rookie question
void OnTriggerEnter(Collider other) { if (other.CompareTag ("Player")) { other.SendMessage ("TakeDamage", 20f); } }
|
|
|
Post by jrackley on Mar 13, 2017 20:09:16 GMT
Okay getting closer anyhow, if I use the following code then the player is damaged on the collision but it throws an error. does anyone know what am I doing wrong here?
using System.Collections; using System.Collections.Generic; using UnityEngine; using Invector; using Invector.CharacterController; using Invector.EventSystems;
public class HitMe : MonoBehaviour { public vCharacter cc; public int damage;
void OnTriggerEnter(Collider other) { if (other.CompareTag ("Player")) { cc.TakeDamage ((Damage)new Damage(damage), true); } }
} Then I get the error....
NullReferenceException: Object reference not set to an instance of an object Invector.CharacterController.vThirdPersonMotor.TakeDamage (.Damage damage, Boolean hitReaction) (at Assets/Invector-3rdPersonController/Basic Locomotion/Scripts/CharacterController/vThirdPersonMotor.cs:319) HitMe.OnTriggerEnter (UnityEngine.Collider other) (at Assets/HitMe.cs:15)
|
|
|
Post by Invector on Mar 13, 2017 21:00:44 GMT
Just curious, why can't you use the vObjectDamage?
|
|
|
Post by jrackley on Mar 13, 2017 21:39:09 GMT
Just curious, why can't you use the vObjectDamage? Trying to see if I can get emerald AI working good. It has the ability to have a custom function or a sendMessage called to apply damage, just cant get it to work out correctly with the above. Last minute hiccups delaying us, lol!
|
|
|
Post by Invector on Mar 13, 2017 22:35:31 GMT
You need to send more information, try this:
if (other.CompareTag("Player")) { var _damage = new Damage(damage); _damage.sender = transform; _damage.hitPosition = transform.position; cc.TakeDamage(_damage, true); }
|
|
|
Post by jrackley on Mar 13, 2017 23:15:23 GMT
Perfect! Thanks once again!
|
|
|
Post by dakurlz on Nov 3, 2017 16:54:45 GMT
Sorry for the newbie question here but I am having a hell of a time trying to figure out how to get my animal to apply damage to the character. I see in the code that it says to use the TakeDamage method to apply damage, however I can not get this to work at all. Here is an example of what I am trying. I know I am not the best coder so any help would be appreciated, I just need the correct method to call and be able to apply damage to the character when it is hit by the animal. And I cannot use the the vObjectDamage for this before it is mentioned(lol). thank you in advance for any help and sorry for the rookie question void OnTriggerEnter(Collider other) { if (other.CompareTag ("Player")) { other.SendMessage ("TakeDamage", 20f); } }
Please, man, can you help me with animals! I cant add Third Person Script for animal, because his is not humanoid! Can you give me a package with simple animal and scripts? It will be very helpfull for me.
|
|