私はこの質問に対する答えを見つけようとしていますが、何も見つかりませんでした。私はシンプルなクリッカーゲームを作成しようとしていますが、始めに立ち往生しています...これはあまり良くありません。私がしようとしていることは、プレイヤーに(+ 1 $を追加するだけで)お金を与え、 "+ 1 $"と言うテキストオブジェクトにスポーンすることです。オブジェクトが現れないようです。私はそれがうまくいくかどうかわからない "アニメーション"も作った。どちらのクラス:タッチ後にオブジェクトがインスタンス化されない
public class TapTextMovement : MonoBehaviour {
private int frameCount = 0;
private float temp;
public int modifier = 0;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
if (frameCount < 40) {
temp = this.transform.position.y + 1F * modifier;
this.transform.position = new Vector3(this.transform.position.x, temp, this.transform.position.z);
} else if (frameCount < 50) {
temp = this.transform.position.y + 0.5F * modifier;
this.transform.position = new Vector3(this.transform.position.x, temp, this.transform.position.z);
} else if (frameCount < 55) {
temp = this.transform.position.y + 0.3F * modifier;
this.transform.position = new Vector3(this.transform.position.x, temp, this.transform.position.z);
} else if (frameCount < 60) {
temp = this.transform.position.y + 0.15F * modifier;
this.transform.position = new Vector3(this.transform.position.x, temp, this.transform.position.z);
} else {
Object.Destroy (this);
}
frameCount++;
}
}
そして:
public class MoneyTap : MonoBehaviour {
public GameObject money;
private Text moneyText;
public long moneyAmount = 0;
public GameObject tapText;
private Vector2 tempPos;
private Vector3 fullPos;
void Start() {
moneyText = money.GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
moneyText.text = moneyAmount + "$";
if (Input.touchCount > 0) {
if (Input.GetTouch (0).phase == TouchPhase.Began) {
tempPos = Input.GetTouch(0).position;
fullPos = new Vector3 (tempPos.x, tempPos.y, 0);
RaycastHit2D hitInfo = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (Input.GetTouch(0).position), Vector2.zero);
if (hitInfo) {
moneyAmount++;;
Instantiate(tapText, fullPos, Quaternion.identity);
}
}
}
}
}
私は助けのすべてのビットをいただければ幸いUnityへのビット新しいです!ありがとう!これが問題の原因となり、パフォーマンスに影響を与えるよう
GameObject go = Instantiate(tapText, fullPos, Quaternion.identity) as GameObject;
はまた、アップデートにアニメーションを作成しない:オブジェクトの利用機能をインスタンス化する
**アップデート**でアニメーションを作成しないでください。これらの変更はフレームレンダリングで1回実行されるため、パフォーマンスに影響します –
代替方法はありますか?なぜそれをしないのですか?私は1秒ごとまたは2秒ごとにフレームの位置を変更し、それを削除したいと思います。各フレームは、オブジェクトが狂った数だけ上がっていきますが、なぜ今はそれが必要でしょうか? –