プレイヤーを破壊しようとしています。自分のプラットフォームにスクリプトを添付して、プレイヤーと衝突してタイマーを開始し、タイマーが終了したら、gameオブジェクト(プラットフォーム自体)を破棄するようにしました。私もそれを持っていたいので、プレイヤーがなくなったときにプレイヤーがプラットフォームに乗ってしまった場合、プレーヤーも破壊されます。だから私はブールを作りましたが、ブールが真ならば、ただプレーヤーを破壊するのは難しいです。Unityでゲームオブジェクトを破壊する方法
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyAddPlatform : MonoBehaviour {
//This will be used to set the seconds
public float timeLeft = 3f;
bool playerOn = false;
private float PlayerGameObject;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
//How you declare a Coroutine Function.
IEnumerator destroyer(){
//wait for the timeLeft in seconds.
yield return new WaitForSeconds (timeLeft);
//Then destroy the object this script is attached to
Destroy (gameObject);
}
//A timer that will start the coroutine
void destroyTimer(){
//coroutine calls the destroyer function, its a function that runs independently.
StartCoroutine ("destroyer");
//At this point tell it to add in a new platform.
}
//This function will be in accordance to a collision.
void OnCollisionEnter2D (Collision2D other){
if (other.gameObject.CompareTag ("Player"))
//If the object is the player, run
destroyTimer();//Start the destroy timer funciton.
}
}
はあなたがしようとしたコードを追加することができれば、タイマーが実行されたときに
が次にチェック設定されていますか?このポストへ –
あなたに私たちに特定の問題とそれを引き起こすコードを与えていないなら、私たちはあなたを助けることはできません。 'unityscript'タグも関連していると確信していますか?あなたが本当にそれを使用しているなら、私は切り替えを提案しています。もしあなたが既にC#を使用しているなら、タグを削除してください:-)。 – George
私は自分のコードを掲載し、unityscriptタグを削除しました。 –