我有一个错误
"类型或命名空间名称' clicker'无法找到。你错过了装配参考吗?
我知道这是装配错误。我在网上搜索了关于assemly错误的信息。 但我不喜欢'我知道如何修改这段代码。
所以我的问题是如何解决这个错误(可能是汇编错误)?
using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
public class ButtonExecute : MonoBehaviour {
public float timeToSelect = 2.0f;
private float countDown;
private GameObject currentButton;
private Clicker clicker = new Clicker();
............
if (currentButton != null) {
countDown -= Time.deltaTime;
if (clicker.Clicked() || countDown < 0.0f){
ExecuteEvents.Execute<IPointerClickHandler>
(currentButton, data,
ExecuteEvents.pointerClickHandler);
countDown = timeToSelect;
}
}
}
}
这是我的整个代码&#34; ButtonExecute.cs&#34;。 抱歉没有提出准确的问题:(
using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
public class ButtonExecute : MonoBehaviour {
public float timeToSelect = 2.0f;
private float countDown;
private GameObject currentButton;
private Clicker clicker = new Clicker();
// Update is called once per frame
void Update () {
Transform camera = Camera.main.transform;
Ray ray = new Ray (camera.position, camera.rotation * Vector3.forward);
RaycastHit hit;
GameObject hitButton = null;
PointerEventData data = new PointerEventData
(EventSystem.current);
if(Physics.Raycast(ray, out hit)){
if(hit.transform.gameObject.tag == "Button"){
hitButton = hit.transform.parent.gameObject;
}
if(currentButton != hitButton){
if(currentButton != null){
ExecuteEvents.Execute<IPointerExitHandler>(currentButton,
data,ExecuteEvents.pointerExitHandler);
}
currentButton = hitButton;
if(currentButton != null){
ExecuteEvents.Execute<IPointerEnterHandler>
(currentButton,data,
ExecuteEvents.pointerEnterHandler);
countDown = timeToSelect;
}
}
if (currentButton != null) {
countDown -= Time.deltaTime;
if (clicker.Clicked() || countDown < 0.0f){
ExecuteEvents.Execute<IPointerClickHandler>
(currentButton, data,
ExecuteEvents.pointerClickHandler);
countDown = timeToSelect;
}
}
}
}
}
答案 0 :(得分:1)
这是一个教程,我认为这可能会帮助其他人遵循相同的教程。你错过了Clicker
课程。您可以在第51页上找到。创建它并将代码放在其中:
using UnityEngine;
using System.Collections;
public class Clicker
{
public bool clicked()
{
return Input.anyKeyDown;
}
}
以及来自if (clicker.Clicked() || countDown < 0.0f){
脚本的ButtonExecute
,如果您想彻底遵循教程,则if (clicker.clicked() || countDown < 0.0f){
应为|
。