-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerRangedAttack.cs
34 lines (25 loc) · 1000 Bytes
/
PlayerRangedAttack.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerRangedAttack : MonoBehaviour{
[Tooltip("Bullet created by player")]
public GameObject bullet;
[Tooltip("Location where shots come out of")]
public Transform bulletSpawn;
private PlayerSettings playerSettings;
private float nextShotAllowed = 0;
void Start(){
playerSettings = PlayerSettings.getInstance();
}
void Update(){
}
public void shoot() {
if(Time.time > nextShotAllowed) {
GameObject shot = Instantiate(bullet, bulletSpawn.position, bulletSpawn.rotation);
Vector3 direction = bulletSpawn.transform.forward.normalized;
Rigidbody rb = shot.GetComponent<Rigidbody>();
rb.AddForce(direction * playerSettings.RangeAttackForce);
nextShotAllowed = Time.time + playerSettings.RangeAttackCooldown;
}
}
}