Difficulty Using RectTransform & Timed Spawning of Tiles
I'm trying to create a side-scrolling, tile-based runner. I wanted to create a system of randomization in tile creation, and I wanted to keep the Player centered on the screen, so the running is simulated by sprite tiles being spawned on the right of the screen and traveling at a fixed rate to the left of the screen.
However, I want to add a linear increase in speed with distance, which wouldn't work with a fixed spawn rate, so I went about finding a method to get the physical size of a GameObject (tile) to calculate the time needed between spawns based on speed and size of tile being spawned.
I can't seem to get it to work, at all- am I missing something here? I've looked over other uses of RectTransform and I can't find any difference, but it's just causing a bunch of errors.
InvalidCastException: Specified cast is not valid. Spawner.Start () (at Assets/Scripts/Spawner.cs:23)
Any thoughts would be appreciated, including improvements to my plan!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
public GameObject obstacle;
public groundObjectMovement gom;
public float timeBetweenSpawn;
private float spawnTime;
public float width;
public float height;
RectTransform rt;
void Start()
{
rt = (RectTransform)obstacle.transform;
width = rt.rect.width;
height = rt.rect.height;
//spawnTime = calculation to find time using gameobj size and speed of travel
}