blob: 8b32fe380e79b0a1ff83fe5aa798aff646523aff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AfterImagePool : MonoBehaviour
{
//public CharacterControl myCharacterControl;
public GameObject targetObject; //Set these manually to the character object you're copying
public Animator targetAnimator; //Set these manually to the character object you're copying
public GameObject prefab; //This is the prefab you made in the scene. It's a parent transform with an animator and AfterImage script on it, with Armature and SkinnedMeshRenderer children
public int poolSize = 10;
public List<AfterImage> afterImages;
public int interval = 10;
public int time = 0;
// Use this for initialization
void Start()
{
afterImages = new List<AfterImage>(poolSize);
for (int i = 0; i < poolSize; i++)
{
GameObject nextAfterImage = Instantiate(prefab);
nextAfterImage.transform.SetParent(this.transform);
nextAfterImage.GetComponent<AfterImage>().targetObject = targetObject; //Game Object Target
nextAfterImage.GetComponent<AfterImage>().targetAnimator = targetAnimator; //Animator Target
nextAfterImage.SetActive(false);
afterImages.Add(nextAfterImage.GetComponent<AfterImage>());
}
}
// Update is called once per frame
void Update()
{
time++;
if (time > interval)
{
time = 0;
AddAfterImage();
}
}
void AddAfterImage()
{
for (int i = 0; i < poolSize; i++)
{
if (!afterImages[i].active)
{
afterImages[i].Activate();
break;
}
}
}
}
|