Skip to content
Permalink
b3715e0b09
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
118 lines (92 sloc) 2.96 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Weapon : MonoBehaviour
{
public Transform firePoint; //where player is shooting from
public GameObject bulletPrefab; //shuriken
public int shots; //amount of shots
public int shurikenDamage = 10; //shuriken damage
public Animator animator; //animator
//Sword
public Transform attackPoint; //point of attack
public float attackRange = .05f; //circular range
public LayerMask enemyLayers; //only hits the enemies on enemy layer
public int attackDamage = 30; //sword damage
public float attackRate = 1.5f;//attack rate per second
float nextAttackTime = .25f;//next attack time
void Update()
{
//shoot if j
if (Input.GetKeyDown(KeyCode.K))
{
Shoot();
}
if (Time.time >= nextAttackTime)
{
if (Input.GetKeyDown(KeyCode.J))
{
Attack();
nextAttackTime = Time.time + 1f / attackRate;
}
}
}
void Shoot()
{
if (shots > 0)
{
animator.SetTrigger("Shuriken");
SoundManagerScript.PlaySound("Throw");
Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
shots = shots - 1;
ShurikenAmount.text = "X: " + shots;
//Damage in Bullet Script
}
else
{
return;
}
}
void Attack()
{
//Attack Animation
animator.SetTrigger("Attack");
SoundManagerScript.PlaySound("Sword");
//Detect enemies
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers );
foreach(Collider2D enemy in hitEnemies)
{
//was getting errors until this, helped recognize layers or something idk
if(enemy.CompareTag("Bee"))
{
enemy.GetComponent<Enemy1>().TakeDamage(attackDamage);
}
if (enemy.CompareTag("Wizard"))
{
enemy.GetComponent<Enemy2>().TakeDamage(attackDamage);
}
if (enemy.CompareTag("Knight"))
{
enemy.GetComponent<Boss>().TakeDamage(attackDamage);
}
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
Debug.Log("We hit" + enemy.name);
}
}
void OnDrawGizmosSelected()
{
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
public Text ShurikenAmount; //text
void OnTriggerEnter2D(Collider2D other) //Pickups
{
if (other.gameObject.CompareTag("NinjaStar")) //If you got the star
{
SoundManagerScript.PlaySound("Collecting");
other.gameObject.SetActive(false); //Star Dissapears
shots = shots + 1; //increase amount of shots
ShurikenAmount.text = "X: " + shots;
}
}
}