拖动圈子游戏对象后没有其他游戏对象获得分数。但是当我拖动这个圈子游戏对象时,最后每个游戏对象都得分。我没有得到问题所在。但是圈子在每个游戏对象后得分 我认为有一些额外的括号在获得得分时被阻挡。即使在任何对象之后圆圈也会得分,但有些对象在某些对象之后无法得分。当我首先丢弃它时,每个游戏对象都会得分,但有时候一些游戏对象在循环或任何其他游戏对象之后没有得分 圈后-----没有对象得分
三角形-----圆形和方形
方形----矩形和圆形矩形----圆
明星----三角形,矩形,圆形
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;
bool circle_score = true,
triangle_score = true,
square_score = true,
star_score = true,
rectangle_score = true;
void Start()
{
score = score;
if ((ans_circle == null || tag_circle == null) || (ans_square == null || tag_square == 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 circle Find");
}
tag_circle = GameObject.FindGameObjectWithTag("circle");
if (tag_circle != null)
{
Debug.Log("circle");
}
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();
checkTagPlace();
}
public void IncrementScore()
{
score = score + 9;
score++;
scoreText.text = "Score: " + score;
}
public void checkTagPlace()
{
Debug.Log("check function run");
if (ans_circle.transform.position.x == tag_circle.transform.position.x)
{
Debug.Log("found position");
if (circle_score == true)
{
IncrementScore();
circle_score = false;
}
}
else if (ans_rectangle.transform.position.x == tag_rectangle.transform.position.x)
{
if (rectangle_score == true)
{
IncrementScore();
rectangle_score = false;
}
}
else if ((ans_square.transform.position.x == tag_square.transform.position.x))
{
if (square_score == true)
{
IncrementScore();
square_score = false;
}
}
else if (ans_triangle.transform.position.x == tag_triangle.transform.position.x)
{
if (triangle_score == true)
{
IncrementScore();
triangle_score = false;
}
}
else if (ans_star.transform.position.x == tag_star.transform.position.x)
{
if (star_score == true)
{
IncrementScore();
star_score = false;
}
}
}
}