i cant find an easy way to make damage the same as traveltime
using UnityEngine; using System.Collections;
public class Bulletphys : MonoBehaviour {
public int damage = 60;
public float currentdamage = 0;
public float Traveltime = 0;
private GameObject hitObj;
// Use this for initialization
void Start () {
currentdamage = damage;
Traveltime = damage;
}
// Update is called once per frame
void FixedUpdate () {
Traveltime -= Time.deltaTime;
damage = currentdamage;
currentdamage = Traveltime;
if (currentdamage <= 1) {
Explode ();
}
}
void OnTriggerEnter() {
Debug.Log ("OnTriggerEnter");
Explode();
}
void OnCollisionEnter(Collision coll) {
Debug.Log ("OnCollisionEnter");
hitObj = coll.gameObject;
Explode();
}
void Explode() {
Destroy (gameObject);
HaveHealth enemyHealth = hitObj.GetComponent<HaveHealth> ();
if (enemyHealth != null) {
enemyHealth.TakeDamage (damage, transform.position);
}
}
}
Comment
Why are you mixing two types?, int and float, if you use this when you try to retrieve the float value something like this 54.352 into the damage, this will be the result 54, remember you can't set a float value into a int value.