我正在做一个简单的拖放统一游戏。当我第一次拖动对象时,它不会给分,但是当我再次拖动对象时,即使我在错误的地方掉下来,也会给分。我使用的标签,以匹配所需的对象在统一标签中找不到第一次拖动
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class sh_score : MonoBehaviour {
static int score = 0;
public Text scoreText;
public GameObject ans_circle;
public GameObject tag_circle;
public GameObject tag_rectangle;
public GameObject ans_rectangle;
public GameObject ans_triangle;
public GameObject tag_triangle;
public GameObject ans_square;
public GameObject tag_square;
public GameObject ans_star;
public GameObject tag_star;
void Start()
{
score = score;
if((ans_circle == null || tag_circle == null) || (ans_rectangle == null || tag_rectangle == null)|| (ans_square == null || tag_square == null) || (ans_triangle == null || tag_triangle == null)|| (ans_star == null || tag_star == null))
{
ans_circle = GameObject.FindGameObjectWithTag("ans_circle");
if (ans_circle != null)
{ Debug.Log("ans Find"); }
tag_circle = GameObject.FindGameObjectWithTag("circle");
if (tag_circle != null)
{
Debug.Log("circle");
}
checkTagPlace();
ans_rectangle = GameObject.FindGameObjectWithTag("ans_rectangle");
if (ans_rectangle != null)
{ Debug.Log("ans Find"); }
tag_rectangle = GameObject.FindGameObjectWithTag("rectangle");
if (tag_circle != null)
{
Debug.Log("rectangle");
}
ans_triangle = GameObject.FindGameObjectWithTag("ans_triangle");
if (ans_triangle != null)
{ Debug.Log("ans Find"); }
tag_triangle = GameObject.FindGameObjectWithTag("triangle");
if (tag_triangle != null)
{
Debug.Log("triangle");
}
ans_star = GameObject.FindGameObjectWithTag("ans_star");
if (ans_star != null)
{ Debug.Log("ans Find"); }
tag_star = GameObject.FindGameObjectWithTag("star");
if (tag_star != null)
{
Debug.Log("star");
}
ans_square = GameObject.FindGameObjectWithTag("ans_square");
if (ans_square != null)
{ Debug.Log("ans Find"); }
tag_square = GameObject.FindGameObjectWithTag("square");
if (tag_square != null)
{
Debug.Log("square");
}
}
}
void update()
{
scoreText.text = score.ToString();
}
public void IncrementScore()
{
score = score + 9;
score++;
scoreText.text = "Score: " + score;
}
public void checkTagPlace()
{
Debug.Log("check function run");
float circle_postion = tag_circle.transform.position.x;
float circle_Tag_positon = ans_circle.transform.position.x;
float triangle_position = tag_triangle.transform.position.x;
float triangle_Tag_positon = ans_triangle.transform.position.x;
float square_postion = tag_square.transform.position.x;
float square_Tag_positon = ans_square.transform.position.x;
float star_postion = tag_star.transform.position.x;
float star_Tag_positon = ans_star.transform.position.x;
float rectangle_position = tag_rectangle.transform.position.x;
float rectangle_Tag_positon = ans_rectangle.transform.position.x;
if ((ans_circle.transform.position.x == tag_circle.transform.position.x))
{
Debug.Log("found position");
IncrementScore();
}
else if ((ans_rectangle.transform.position.x == tag_rectangle.transform.position.x))
{
IncrementScore();
}
else if ((ans_square.transform.position.x == tag_square.transform.position.x))
{
IncrementScore();
}
else if (ans_triangle.transform.position.x == tag_triangle.transform.position.x)
{
IncrementScore();
}
else if (ans_star.transform.position.x == tag_star.transform.position.x)
{
IncrementScore();
}
}
}
无效更新()需要以大写字母U – JeanLuc
仍然相同的错误 – jiya