Untitled
unknown
plain_text
3 years ago
1.6 kB
6
Indexable
using System.Collections; using System.Collections.Generic; using UnityEngine; public class BanzaiBlaster : MonoBehaviour { private int health = 10; private int level = 1; private int damage = 2; private int characterID; public static int characterIDtohit; public static int damagetodo; public static bool targetlocked; public static bool player1hit; // Start is called before the first frame update void Start() { characterID = Random.Range(0, 1000); Debug.Log(characterID); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A) && targetlocked == true) { damagetodo = 2 * damage; player1hit = true; targetlocked = false; Debug.Log("DamageSent"); } if(characterIDtohit == characterID && player1hit == true) { player1hit = false; health = health - damagetodo; Debug.Log(health + " " + characterID); } if (Input.GetMouseButtonDown(0)) { CastRay(); } } void CastRay() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity); if (hit.collider !=null) { Debug.Log (hit.collider.gameObject.name); characterIDtohit = characterID; targetlocked = true; } } }
Editor is loading...