화합에 문제가 있습니다. 적과 플레이어가 충돌하면 플레이어가 건강 상태를 잃어 버리게하려고합니다. 내 코드는 다음과 같습니다.적과 충돌하여 데미지를 입힌다
코드를 살펴보기 전에 적을 강체로 사용하여 개체의 총알이 효과를 낼 수 있다고 말하고 싶습니다. 코드가 충돌을 감지 할 수 있도록 견고한 몸체가 될 수있는 플레이어 몸체의 한 부분으로 여분의 캡슐을 만들었습니다. 그게 효과가 있다고 생각하니? 강체가 다른 강체 충돌을 감지하는 것이 더 쉬운 지 또는 신경 쓰지 않는지 확실하지 않습니다.
//basic stuff//
public class playerhealth : MonoBehaviour {
private int curHealth;
private int playerLives;
public GUIText winText;
public GUIText healthText;
public GUIText livesText;
void Start(){
curHealth = 3;
playerLives = 3;
SetHealthText();
SetLivesText();
winText.text = "";
}
void FixedUpdate()//where physics codes go
{
}
//HERE'S WHERE THE COLLISIONS STUFF IS
void OnCollisionEnter(Collider rigidbody){
if(rigidbody.gameObject.tag == "Enemy"){
curHealth = curHealth - 1;
SetHealthText();
}
if(rigidbody.gameObject.tag == "reloader"){
playerLives = playerLives - 1;
SetLivesText();
}
}
//setting GUI TEXT and reloading level
void SetHealthText(){
healthText.text = "Health Points: " + curHealth.ToString();
if(curHealth <=0) {
Application.LoadLevel ("shootingworld");
playerLives = playerLives - 1;
}
if(curHealth >= 10){
playerLives+= 1;
}
}
void SetLivesText(){
livesText.text = "Lives: " + playerLives.ToString();
if (playerLives <= 0){
winText.text = "GAME OVER";
}
}
}
당신이 가지고있는 문제를 설명하십시오 수 있습니다. 그리고 시나리오 –