現在Unityでオリジナルゲームの開発中で、プレイヤーが透明な壁を通り抜けたら、敵が動き、20秒後にdestroyされるというコードを書いて実際に動いてくれたのですが、20秒経って破壊されると以下の画像のとおりエラーが出てしまいます。
解決方法を教えていただきたいです。
追伸 コードはこちらになります。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EnemyController : MonoBehaviour
{
public float speed;
public bool Driving = false;
public GameObject car;
void Start()
{
}
void Update()
{
if(Driving == true)
{
car.transform.position -= new Vector3(speed * Time.deltaTime, 0, 0);
Destroy(car, 20f);
}
}
void OnTriggerEnter(Collider col)
{if(col.gameObject.tag == "Player")
{
Driving = true;
}
}
}
回答1件
あなたの回答
tips
プレビュー