-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet2.cs
More file actions
54 lines (48 loc) · 1.68 KB
/
Copy pathbullet2.cs
File metadata and controls
54 lines (48 loc) · 1.68 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This class contain the script for the second type of bullet game object.
public class bullet2 : MonoBehaviour
{
public float speed;
private Vector2 distination;
private Vector2 startpt;
private float percentComplete;
// Update is called once per frame to update the movement of the bullet object
void FixedUpdate()
{
if (gameObject.activeSelf == true)
{
if(percentComplete >= 1.0f)
{
gameObject.SetActive(false);
}
percentComplete += Time.deltaTime / speed;
float currentHeight = Mathf.Sin(Mathf.PI * percentComplete);
if (distination.y - startpt.y < 0)
{
transform.position = Vector2.Lerp(startpt, distination, percentComplete) + Vector2.down * currentHeight;
}
else
{
transform.position = Vector2.Lerp(startpt, distination, percentComplete) + Vector2.up * currentHeight;
}
}
}
//As this bullet type uses object pooling, this function set the position of the bullet when it "fired" by setting it position and setting it active.
void OnEnable()
{
startpt = transform.position;
distination = Weapon.mousePos;
}
//Set the neccessasry variable back to their initial value on disable.
void OnDisable()
{
percentComplete = 0.0f;
}
//Disable the game object on collision with other objects.
void OnCollisionEnter2D(Collision2D collision)
{
gameObject.SetActive(false);
}
}