- Home /
This question was
closed Oct 28, 2017 at 07:28 PM by
wolfartiststudio for the following reason:
found solution
Question by
wolfartiststudio · Oct 28, 2017 at 07:15 PM ·
c#scripting problemerrortransform
Error CS0029: Cannot implicitly convert type to UnityEngine.UI.Transform
I keep getting error CS0029 in line 127. Does anyone know how to deal with this? Code (it's still unfinished):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Parallaxer : MonoBehaviour {
class PoolObject
{
public Transform transform;
public bool inUse;
public PoolObject(Transform t) { transform = t; }
public void Use() { inUse = true; }
public void Dispose() { inUse = false; }
}
[System.Serializable]
public struct YSpawnRange
{
public float min;
public float max;
}
public GameObject Prefab;
public int poolSize;
public float shiftSpeed;
public float spawnRate;
public YSpawnRange ySpawnRange;
public Vector3 deflautSpawnPos;
public bool spawnImmediate;
public Vector3 immediateSpawnPos;
public Vector2 targetAspectRatio;
float spawnTimer;
float targetAspect;
PoolObject[] poolObjects;
Game_Manager game;
void Awake()
{
Configure();
}
void Start()
{
game = Game_Manager.Instance;
}
void OnEnable()
{
Game_Manager.OnGameOverComfirmed += OnGameOverComfirmed;
}
void OnDisable()
{
Game_Manager.OnGameOverComfirmed -= OnGameOverComfirmed;
}
void OnGameOverComfirmed()
{
}
void Update()
{
}
void Configure()
{
targetAspect = targetAspectRatio.x / targetAspectRatio.y;
poolObjects = new PoolObject[poolSize];
for (int i = 0; i < poolObjects.Length; i++)
{
GameObject go = Instantiate(Prefab) as GameObject;
Transform t = go.transform;
t.SetParent(transform);
t.position = Vector3.one * 1000;
poolObjects[i] = new PoolObject(t);
}
if (spawnImmediate)
{
SpawnImmediate();
}
}
void Spawn()
{
Transform t = GetPoolObject();
if (t == null) return;
Vector3 pos = Vector3.zero;
pos.x = deflautSpawnPos.x;
pos.y = Random.Range(ySpawnRange.min, ySpawnRange.max);
t.position = pos;
}
void SpawnImmediate()
{
}
void Shift()
{
for (int i = 0; i < poolObjects.Length; i++)
{
poolObjects[i].transform.position += -Vector3.right * shiftSpeed * Time.deltaTime;
CheckDisposeObject(poolObjects[i]);
}
}
void CheckDisposeObject(PoolObject poolObject)
{
if(poolObject.transform.position.x < -deflautSpawnPos.x)
{
poolObject.Dispose();
poolObject.transform.position = Vector3.one * 1000;
}
}
Transform GetPoolObject()
{
for (int i = 0; i < poolObjects.Length; i++)
{
if(!poolObjects[i].inUse ) {
poolObjects[i].Use();
return poolObjects[i];
}
}
return null;
}
}
Comment