private void SetValues(SpriteTrailObject trailObject) { Vector3 newPosition = transform.position + Vector3.forward * .1f; trailObject.transform.position = newPosition; trailObject.transform.eulerAngles = transform.eulerAngles; trailObject.transform.localScale = transform.localScale; trailObject.SetSpawnValues(_spriteRenderer, this, _rainbowMode ? _rainbowColors : _userSelectedColorPalette); }
private GameObject SpawnTrailObject() { Vector3 newPosition = transform.position + Vector3.forward * .1f; GameObject newGameobject = new GameObject(); newGameobject.AddComponent <SpriteRenderer>(); newGameobject.AddComponent <SpriteTrailObject>(); newGameobject.GetComponent <SpriteRenderer>().flipX = true; newGameobject.transform.position = newPosition; newGameobject.transform.eulerAngles = transform.eulerAngles; newGameobject.transform.localScale = transform.localScale; SpriteTrailObject trailObject = newGameobject.GetComponent <SpriteTrailObject>(); trailObject.SetSpawnValues(_spriteRenderer, this, _rainbowMode ? _rainbowColors : _userSelectedColorPalette); newGameobject.name = "SpriteTrailObject"; return(newGameobject); }
private void Update() { if (_spawnType == SpawnType.TIME && Time.time - _lastSpawnTime >= _timeBetweenTrailSpawn) { SpriteTrailObject trailObject = _spriteObjects.GetObjectFromPool(); SetValues(trailObject); trailObject.gameObject.SetActive(true); _lastSpawnTime = Time.time; } else if (_spawnType == SpawnType.DISTANCE && (_lastSpawnLocation - (Vector2)transform.position).magnitude > _distanceBetweenTrailSpawn) { SpriteTrailObject trailObject = _spriteObjects.GetObjectFromPool(); SetValues(trailObject); trailObject.gameObject.SetActive(true); _lastSpawnLocation = transform.position; } }