| 12
 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
 108
 109
 110
 111
 
 | using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class BOOM : MonoBehaviour 
{
 
	[SerializeField]
	private float fireRate = 0;
 
	[SerializeField]
	private float Damage = 250f;
 
	[SerializeField]
	private LayerMask NotToHit;
 
	private float timeToFire = 0; 
 
	private Transform firePoint;
 
	[SerializeField]
	private Transform BulletTrailPrefab;
 
	[SerializeField]
	private Transform FlashPrefab;
 
	private Player player;
 
	private void Awake()
	{
		firePoint = transform.GetChild(0);
 
		if (firePoint == null)
		{
			Debug.Log ("PLEASE");
		}
	}
 
	private void Start()
	{
		player = GameManager.Instance.playerinstantiate.GetComponent<Player>();
	}
 
	void Update () 
	{
		if (fireRate == 0) 
		{
			if (Input.GetMouseButton (0)) 
			{
				Shoot ();
			}
		} else if (Input.GetMouseButton (0) && Time.time > timeToFire) 
		{
			timeToFire = Time.time + 1 / fireRate;
			Shoot();
		}
 
 
	}
 
	private void Shoot ()
	{
		Vector3 mousePositionWorld = Camera.main.ScreenToWorldPoint (Input.mousePosition);
 
		Vector2 mousePosition = new Vector2 (mousePositionWorld.x, mousePositionWorld.y);
 
		Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);
 
		RaycastHit2D hit = Physics2D.Raycast (firePointPosition, mousePosition - firePointPosition, Mathf.Infinity, NotToHit);
 
 
 
		Debug.DrawLine(firePointPosition, (mousePosition - firePointPosition)* 100);
 
		if (hit.collider != null)
 
		{
 
			Debug.DrawLine (firePointPosition, hit.point, Color.red);
 
			if (hit.collider.tag == "enemy")
			{
				Debug.Log ("TOUCHE");
				Debug.DrawLine (firePointPosition, hit.point, Color.cyan);
				EnemyFoght enemy = hit.collider.GetComponent<EnemyFoght> ();
				player.Attack (enemy);
			} 
			}
				Effect();
		}
 
 
 
 
	private void Effect()
	{
		Instantiate (BulletTrailPrefab, firePoint.position, firePoint.rotation);
 
		Transform Flash = Instantiate (FlashPrefab, firePoint.position, firePoint.rotation) as Transform;
 
		float size = Random.Range (0.6f, 0.9f);
 
		Flash.localScale = new Vector3 (size, size, size);
		Destroy (Flash.gameObject, 0.2f);
	}
 
 
 
 
 
} | 
Partager