Exemple #1
0
 void Shoot()
 {
     Debug.Log ("Weapon Fired");
     Vector2 mousePosition = new Vector2 (Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
     Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);
     RaycastHit2D hit = Physics2D.Raycast (firePointPosition, mousePosition-firePointPosition, 100, whatToHit); //Draw raycast from fire point on model (tip of gun) to mouse position with 100 length
     //Debug.DrawLine (firePointPosition, (mousePosition-firePointPosition)*100, Color.cyan);
     if (Time.time >= timeToSpawnEffect) {
         StartCoroutine("Effect");
         timeToSpawnEffect = Time.time + 1/effectSpawnRate;
     }
     if (hit.collider != null) {
         //Debug.DrawLine (firePointPosition, hit.point, Color.red); Red to denote a successful hit
         Debug.Log ("We hit " + hit.collider.name + " and did " + damage + " damage.");
         enemyHealth = hit.collider.GetComponent<EnemyHealth>();
         enemyHealth.SetHitPoints(damage);
     }
 }