void SpawnEnemyPrefab() { //Spawns enemy at the location of SpawnPoint game object enemy_main spawnedEnemy = Instantiate(spawnPrefab, transform.position, transform.rotation); spawnedEnemy.where_to_go = initialMoveTarget; }
// Update is called once per frame void Update() { inputVertical = new Vector3(0, 1, 0) * Input.GetAxis("Vertical"); inputHorizontal = new Vector3(1, 0, 0) * Input.GetAxis("Horizontal"); RaycastHit hit; if (Input.GetAxis("Horizontal") != 0) { raySetDirection = new Ray(this.transform.position, inputHorizontal); kickedDirection = inputHorizontal; } else if (Input.GetAxis("Vertical") != 0) { raySetDirection = new Ray(this.transform.position, inputVertical); kickedDirection = inputVertical; } rayCurrentDirection = raySetDirection; if (Physics.Raycast(rayCurrentDirection, out hit, rayLength)) { if (hit.collider.tag == "Enemy" && Input.GetKeyDown(KeyCode.E)) { Debug.Log("Enemy Kicked"); scriptAObject = hit.collider.gameObject; scriptA = scriptAObject.GetComponent <enemy_main>(); scriptA.being_kicked(kickedDirection); } } }
// ask a node for new target public enemy_target update_target(enemy_main curr_enemy) { float distance = Vector3.Distance(curr_enemy.transform.position, this.transform.position); //Debug.Log(distance); if (distance > arrival_radius || !next_target) { return(this); } return(next_target); }
// ask a node for new target public enemy_target update_target(enemy_main curr_enemy) { // determine distance between an enemy and the target float distance = Vector3.Distance(curr_enemy.transform.position, this.transform.position); // If the enemy has arrived, guide to the next target if (distance > arrival_radius || !next_target) { return(this); } return(next_target); }
// Update is called once per frame void Update() { timer(); if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.F)) { if (kickCooldown > cooldownTimer) { isKicking = true; kickNow = true; animator.SetBool("Kick", kickNow); Debug.Log("MouseDown"); var screenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0); screenPoint.z = 10.0f; newLocation = Camera.main.ScreenToWorldPoint(screenPoint); kickedDirection = Vector3.Normalize(newLocation - this.transform.position); Debug.Log(kickedDirection); Debug.DrawRay(this.transform.position, kickedDirection * rayLength, Color.black); RaycastHit2D hit = Physics2D.Raycast(this.transform.position, kickedDirection, rayLength); if (scriptB.kickLeft == true) { kickDirection = -1; animator.SetFloat("KickLeft", kickDirection); } else if (scriptB.kickLeft == false) { kickDirection = 1; animator.SetFloat("KickLeft", kickDirection); } if (hit.collider.tag == "Enemy") { scriptAObject = hit.collider.gameObject; scriptA = scriptAObject.GetComponent <enemy_main>(); Debug.Log("Kicking"); scriptA.being_kicked(kickedDirection); kickCooldown = 0; } } } else { kickNow = false; animator.SetBool("Kick", kickNow); isKicking = false; } }