PUN trigger checking problem
banshee
✭
I'm having a problem with this script. It's supposed to set inRange to true when the killer enters a certain collider. The inRange boolean however, instantly gets set to true when the killer spawns, and he can hit any time he wants to.
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class killerHit : MonoBehaviour {
public bool inRange;
public bool hitCooldown;
public PhotonView photonView;
public playerStats playerStats;
// Use this for initialization
void Start () {
hitCooldown = false;
inRange = false;
}
// Update is called once per frame
void Update () {
if(photonView.isMine) {
if(Input.GetButtonDown("Fire1")) {
if(inRange == true) {
Hit();
} else {
Debug.Log("Killer not in range ...");
}
}
}
}
void OnTriggerStay(Collider other) {
if(other.gameObject.tag == "Player")
Debug.Log("Reached player hitbox ...");
inRange = true;
}
void OnTriggerExit(Collider other) {
if(other.gameObject.tag == "Player")
Debug.Log("Left player hitbox ...");
inRange = false;
}
public void Hit () {
if(hitCooldown == false)
playerStats.playerHealth = playerStats.playerHealth - 1;
Debug.Log("Player hit for 1 ...");
}
public IEnumerator HitCD () {
hitCooldown = true;
yield return new WaitForSeconds(3);
hitCooldown = false;
}
}
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class killerHit : MonoBehaviour {
public bool inRange;
public bool hitCooldown;
public PhotonView photonView;
public playerStats playerStats;
// Use this for initialization
void Start () {
hitCooldown = false;
inRange = false;
}
// Update is called once per frame
void Update () {
if(photonView.isMine) {
if(Input.GetButtonDown("Fire1")) {
if(inRange == true) {
Hit();
} else {
Debug.Log("Killer not in range ...");
}
}
}
}
void OnTriggerStay(Collider other) {
if(other.gameObject.tag == "Player")
Debug.Log("Reached player hitbox ...");
inRange = true;
}
void OnTriggerExit(Collider other) {
if(other.gameObject.tag == "Player")
Debug.Log("Left player hitbox ...");
inRange = false;
}
public void Hit () {
if(hitCooldown == false)
playerStats.playerHealth = playerStats.playerHealth - 1;
Debug.Log("Player hit for 1 ...");
}
public IEnumerator HitCD () {
hitCooldown = true;
yield return new WaitForSeconds(3);
hitCooldown = false;
}
}
0
Comments
-
Bump0
-
Bump once again0