в принципе он атакует только через раз
Синтаксис:
Используется csharp
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DungeonKIT
{
public class PlayerCombat: PlayerATK
{
PlayerController plController;
GameObject enemy;
[Header("Prefabs")]
public GameObject rangeWeapon; //Prefab Throwing Weapons
[Header("Parametrs")]
public float timeBtwShots; //time between shots
public float startTimeBtnShots; // Start time between shots
private void Start()
{
}
public void Update()
{
enemy = GameObject.FindGameObjectWithTag("Enemy");
plController = GetComponent<PlayerController>();
if (Input.GetKey(KeyCode.Mouse0))
{
AttackByRate(); //Attack
}
}
//Method of attack
public override void RangeAttack(GameObject rangeWeapon, Transform target)
{
//Set up here
//
base.RangeAttack(rangeWeapon, target);
}
//AttackByRate method
void AttackByRate()
{
if (Vector2.Distance(transform.position, enemy.transform.position) < plController.radiusAttack) //If a player is in radiusAttack
/// if (timeBtwShots <= 0)
{
RangeAttack(rangeWeapon, enemy.transform); //Spawn weapon
timeBtwShots = startTimeBtnShots;//Set time to start again
}
else
{
timeBtwShots -= Time.deltaTime;//Time minus 1 sec
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DungeonKIT
{
public class PlayerCombat: PlayerATK
{
PlayerController plController;
GameObject enemy;
[Header("Prefabs")]
public GameObject rangeWeapon; //Prefab Throwing Weapons
[Header("Parametrs")]
public float timeBtwShots; //time between shots
public float startTimeBtnShots; // Start time between shots
private void Start()
{
}
public void Update()
{
enemy = GameObject.FindGameObjectWithTag("Enemy");
plController = GetComponent<PlayerController>();
if (Input.GetKey(KeyCode.Mouse0))
{
AttackByRate(); //Attack
}
}
//Method of attack
public override void RangeAttack(GameObject rangeWeapon, Transform target)
{
//Set up here
//
base.RangeAttack(rangeWeapon, target);
}
//AttackByRate method
void AttackByRate()
{
if (Vector2.Distance(transform.position, enemy.transform.position) < plController.radiusAttack) //If a player is in radiusAttack
/// if (timeBtwShots <= 0)
{
RangeAttack(rangeWeapon, enemy.transform); //Spawn weapon
timeBtwShots = startTimeBtnShots;//Set time to start again
}
else
{
timeBtwShots -= Time.deltaTime;//Time minus 1 sec
}
}
}
}