When the player comes into collision with the enemy it will have this god awful horrible lagg for some unknown reason it could be because of my script. It could be because of the collision itself, but probably my script. I’ll attach the script down below.
function Update() {
if(Input.GetMouseButtonDown(0)) {
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray,hit, 100.0)) {
if(hit.collider != null) {
attack(hit.collider.name,hit.collider.tag);
}
}
}
if(Input.GetKeyDown("escape")) {
Screen.lockCursor = false;
}
}
function attack(enemy,tag) {
if (tag == "enemy") {
pLife = player.GetComponent(playerStats).pLife;
pStamina = player.GetComponent(playerStats).pStamina;
pMeleeSkill = player.GetComponent(playerStats).pMeleeSkill;
pGunSkill = player.GetComponent(playerStats).pGunSkill;
pCraftingSkill = player.GetComponent(playerStats).pCraftingSkill;
pHead = player.GetComponent(playerStats).pHead;
pLeftHand = player.GetComponent(playerStats).pLeftHand;
pRightHand = player.GetComponent(playerStats).pRightHand;
pChest = player.GetComponent(playerStats).pChest;
pLeftHandWeapon = player.GetComponent(playerStats).pLeftHandWeapon;
pRightHandWeapon = player.GetComponent(playerStats).pRightHandWeapon;
//var
var damage: float;
if (pRightHandWeapon != "none" && pLeftHandWeapon == "none") {
//damage = (*(WeaponDamage*1.75));
}
else if (pRightHandWeapon != "none" && pLeftHandWeapon != "none") {
//damage = ;
}
else {
damage = ((pMeleeSkill*5)+7.25)*0.85;
}
GameObject.Find(enemy).GetComponent(zStats).eLife -= damage;
Debug.Log(GameObject.Find(enemy).GetComponent(zStats).eLife);
}
}
I use a mesh collider. Could it be that as the issue?