summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Effects/AfterImage/AfterImage.cs
blob: 7f40e11940d5da5d55bb9e8223cab7cfcf96a4a9 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AfterImage : MonoBehaviour
{
	public Animator myAnimator;
	//public CharacterControl myCharacterControl;
	public Renderer[] myRenderers;

	public Animator targetAnimator;
	public GameObject targetObject;

	public float time;
	public float intensity;
	public float pow;
	public float timeMax = 45;

	public bool active;

	// Use this for initialization
	void Start()
	{
		//targetObject = 
	}

	// Update is called once per frame
	void Update()
	{
		if (time > 0)
		{
			time--;
			active = true;
			intensity = (time / timeMax) * 10 * pow;
			UpdateRenderer();
		}
		else
		{
			active = false;
			intensity = 0;
            this.transform.gameObject.SetActive(false);
		}
	}

	void UpdateRenderer()
	{
        foreach(var renderer in myRenderers)
        {
            for(int i = 0;i < renderer.materials.Length; ++i)
			{
				renderer.materials[i].SetFloat("_Intensity", intensity);
                renderer.materials[i].SetFloat("_MKGlowPower", intensity);
            }
        }
    }

	public void Activate()
	{
		active = true;
		transform.position = targetObject.transform.position;
		transform.localScale = targetObject.transform.lossyScale;
		transform.rotation = targetObject.transform.rotation;
        transform.gameObject.SetActive(true);

		myAnimator.Play(targetAnimator.GetCurrentAnimatorStateInfo(0).shortNameHash, 0, targetAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime);

		myAnimator.speed = 0.02f;
		myAnimator.Update(1/60f);
		time = timeMax + 1;
		Update();
	}

}