Вот и весь сценарий сэр. Проблема в том, что когда я выпущу. Там будут две монеты, которые будут появляться вместо одного. спасибо за помощьПочему я получаю 2 выхода?
using UnityEngine;
using System.Collections;
public class coinControler : MonoBehaviour {
int flag;
int x = 0;
float xScale = 0.3f;
float zScale = 0.3f;
float xInterval = 0.01f;
float zInterval = 0.01f;
public GameObject coinobj;
public GameObject coin0;
Vector3 scale;
// Use this for initialization
void Start(){
//for 1st coin
scale = coinobj.transform.localScale;
scale.z = zScale;
scale.x = xScale;
coinobj.transform.localScale = scale;
//for 2nd coin
scale = coin1.transform.localScale;
scale.z = zScale;
scale.x = xScale;
}
// Update is called once per frame
void Update() {
touchInput();
}
void touchInput() {
//interval of the coin growth
if(x%20 == 0 && x >= 20)
{
xInterval += 0.01f;
zInterval += 0.01f;
}
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Began)
{
//Change Scale
if (flag == 0)
{
scale.x += xInterval;
scale.z += zInterval;
coinobj.transform.localScale = scale;
Debug.Log("......" + x + "........");
x++;
}
}
//the coin will drop after the user releases touch
else
{
//drop the coin
coinobj.AddComponent<Rigidbody>();
if (flag == 0)
{
coinSpawn0();
Debug.Log("Drop Coin");
}
}
}
}
//Spawn function of the second coin
public void coinSpawn0()
{
Vector3 coinPos = new Vector3(transform.position.x, transform.position.y, transform.position.z);
Instantiate(coin0, coinPos, Quaternion.identity);
scale = coin0.transform.localScale;
scale.z = zScale;
scale.x = xScale;
coin0.transform.localScale = scale;
xInterval = 0.01f;
zInterval = 0.01f;
flag = 1;
}
}
Выход:
...... 42 ........ UnityEngine.Debug: Log (Object)
... ... 42 ........ UnityEngine.Debug: Log (Object)
...... 43 ........ UnityEngine.Debug: Log (Object)
...... 43 ........ UnityEngine.Debug: Лог (Объект)
Показать Флаг: 1 UnityEngine.Debug: Лог (Объект)
Показать Флаг: 1 UnityEngine.Debug: Log (Object)
В чем проблема? –
, как вы можете видеть. im получает 2 выхода. это должно быть 42 43 и только флаг 1. им жаль im новичок в этом –
положить весь сценарий. –