【发布时间】:2016-10-18 13:00:30
【问题描述】:
我正在努力做到这一点,以便在您收集到 20 个硬币时打开一扇统一的门。然后当你触摸它时它会打开。但出于某种原因。当我用 0、1、2 等硬币触摸它时,它仍然会打开。我该如何防止这种情况?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Player_Controller : MonoBehaviour {
public float speed;
public Text countText;
private Rigidbody rb;
private int count;
public float volume;
public Text eye;
AudioSource audio;
void Start()
{
audio = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
eye.text = "";
}
void FixedUpdate()
{
float moveHorizonal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizonal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("pickup"))
{
audio.Play(); //Play it
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
else if (other.gameObject.CompareTag("pickup2"))
{
audio.Play(); //Play it
other.gameObject.SetActive(false);
count = count + 10;
SetCountText();
}
else if (other.gameObject.CompareTag("eye"))
{
audio.Play(); //Play it
other.gameObject.SetActive(false);
count = count + 9999999;
SetCountText();
}
else if (other.gameObject.CompareTag("door") && count <= 20)
{
other.gameObject.SetActive(false);
count = 0;
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 9001)
{
eye.text = "You hit the bull's eye! ALL THE POINTS!";
}
}
}
更新:我在这里使用了错误的字符。 。但是现在的问题是,由于它是触发器,因此您可以直接通过。我怎样才能让它稳固,但仍然是一个触发器?
【问题讨论】: