Question by
unity_q3nZ52RXZ2UP2g · Sep 16, 2017 at 08:54 PM ·
collisiondamagecalculation
Damage gets multiplied for some reason.
So I made a collision damage script but for some reason the variables get multiplied but it works fine if I stand at certain angles.
Script for enemy projectiles. It sometimes multiplies x2:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ebulletdamage : MonoBehaviour {
public float damage = -10;
public float lifetime = 0.5f;
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Player")
{
other.gameObject.GetComponent<playerhealth>().ChangeHealth(damage);
Destroy(gameObject);
}
}
void Update()
{
Destroy(gameObject, lifetime);
}
}
Player health:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerhealth : MonoBehaviour
{
public float maxHealth = 100f;
public float curHealth = 100f;
void start()
{
}
void Update()
{
}
public void ChangeHealth(float PAmount)
{
curHealth += PAmount;
}
}
Medkit. It gets multiplied x4:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class medkit : MonoBehaviour {
public float heal = 10;
// Use this for initialization
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Player")
{
other.gameObject.GetComponent<playerhealth>().ChangeHealth(heal);
Destroy(gameObject);
}
}
}
Comment