blob: a1434d81305105f5731b8fb5c6b80df235c3bbc5 (
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestPseudoVec3
{
public float x;
public float y;
public float h;
public TestPseudoVec3(float x, float y, float h)
{
this.x = x;
this.y = y;
this.h = h;
}
}
public class TestGrenade : MonoBehaviour
{
public bool useGravity;
public float gravity = -9.8f;
public TestPseudoVec3 velocity;
public TestPseudoVec3 pseudoPos;
public Transform shadow;
private bool m_IsGround
{
get
{
return pseudoPos.h <= 0;
}
}
// Start is called before the first frame update
void Start()
{
//Invoke("Dead", 3);
}
void Dead()
{
if (this.gameObject)
{
GameObject.Destroy(this.gameObject);
}
}
// Update is called once per frame
void Update()
{
if(useGravity && !m_IsGround)
{
velocity.h += gravity * Time.deltaTime;
}
pseudoPos.x += velocity.x * Time.deltaTime;
pseudoPos.y += velocity.y * Time.deltaTime;
pseudoPos.h += velocity.h * Time.deltaTime;
if(m_IsGround)
{
velocity.h = -velocity.h;
pseudoPos.h = 0;
}
Vector3 position = transform.position;
position.x = pseudoPos.x;
position.y = pseudoPos.y + pseudoPos.h;
transform.position = position;
if (shadow)
{
// shadow position
shadow.rotation = Quaternion.identity;
Vector3 shadowPos = Vector3.zero;
shadowPos.x = pseudoPos.x;
shadowPos.y = pseudoPos.y;
shadowPos.z = 0;
shadow.position = shadowPos;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
//GameObject go = collision.gameObject;
//if (!go.CompareTag("enemy"))
//{
// return;
//}
//GameObject.Destroy(collision.gameObject);
////this.gameObject.SetActive(false);
//if (this.gameObject)
//{
// GameObject.Destroy(this.gameObject);
//}
}
}
|