49 lines
1.4 KiB
C#
Executable File
49 lines
1.4 KiB
C#
Executable File
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class TrailMgrSolo : MonoBehaviour
|
|
{
|
|
public Component controller;
|
|
public TrailRenderer trail;
|
|
|
|
public Vector3[] positions;
|
|
public Transform trailPoolParent;
|
|
public GameObject trailColliderObj;
|
|
public List<GameObject> trailsPool;
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
positions = new Vector3[trail.positionCount];
|
|
int length = trail.GetPositions(positions);
|
|
if(length > trailsPool.Count){
|
|
//must create new trails
|
|
int missingCount = length - trailsPool.Count;
|
|
for(int i =0; i < missingCount; i++){
|
|
GameObject newTrail = Instantiate(trailColliderObj, trailPoolParent);
|
|
// Debug.Log("Spawned new trail obj " + newTrail.name);
|
|
newTrail.GetComponent<TrailColliderSolo>().trailMgr = this;
|
|
trailsPool.Add(newTrail);
|
|
}
|
|
}
|
|
for(int i =0; i < trailsPool.Count; i++){
|
|
if(i < length){
|
|
trailsPool[i].SetActive(true);
|
|
trailsPool[i].transform.position = positions[i];
|
|
}else{
|
|
trailsPool[i].SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnColliderHit(Collider2D hit){
|
|
controller.BroadcastMessage("TrailCollided",hit);
|
|
// Debug.Log("Got hit:" +hit.name);
|
|
}
|
|
}
|