내 선수가 무한 러너처럼 실행되도록 경로를 생성하는 스크립트를 만들고있었습니다. 내 "자체"변환 (선수의 tranform)에 액세스하려고 시도하고 그것을 playertransform 변수에 넣었지만이 오류가 발생했습니다. heres는 전체 코드 : - 당신은 gameObject
의 배열을 반환 FindGameObjectsWithTag()
사용하는'UnityEngine.GameObject []'에 '변환'오류에 대한 정의가 없습니다.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class tilemanager : MonoBehaviour {
public GameObject[] tileprefabs;
private Transform playertransform;
private float spawnz = 0.0f;
private float tilelength = 16.0f;
private int amountoftilesonscreen = 7;
private List<GameObject> activetiles;
private float safezone = 15.0f;
void Start(){
activetiles = new List<GameObject>();
playertransform = GameObject.FindGameObjectsWithTag("Player").Transform;
for(int i = 0; i < amountoftilesonscreen; i++){
SpawnTile();
}
}
void Update(){
if(playertransform.position.z - safezone > (spawnz - amountoftilesonscreen * tilelength)){
SpawnTile();
DeleteTile();
}
}
void SpawnTile(int prefabIndex = -1){
GameObject go;
go = Instantiate(tileprefabs[0]) as GameObject;
go.transform.SetParent(transform);
go.transform.position = Vector3.forward * spawnz;
spawnz += tilelength;
activetiles.Add(go);
}
void DeleteTile(){
Destroy(activetiles[0]);
activetiles.RemoveAt(0);
}
}
FindGameObjectsWithTag는 Array를 반환하고 Transform은 Array 클래스의 속성이 아닙니다. – ojf