ЭТО ПЕРВЫЙ СКРИПТ ИЗ НЕГО НУЖНО ВЗЯТЬ КЛАСС (STOP)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class combatPlaye: MonoBehaviour
{
public Animator anim;
public Transform AttackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public Vector2 moveVector;
public int attackDamage = 40;
public float attackRate = 2f;
float nextAttackTime = 0f;
void Update()
{
if(Time.time >= nextAttackTime)
{
if (Input.GetKeyDown(KeyCode.F))
{
Attack();
nextAttackTime = Time.time + 1f / attackRate;
}
}
}
void Attack()
{
// АНІМАЦІЯ АТАКИ
anim.SetTrigger("Attack");
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(AttackPoint.position, attackRange, enemyLayers);
foreach(Collider2D enemy in hitEnemies)
{
enemy.GetComponent<WraithController>().TakeDamage(attackDamage);
}
}
void OnDrawGizmosSelected()
{
if (AttackPoint == null)
return;
Gizmos.DrawWireSphere(AttackPoint.position, attackRange);
}
public void Stop()
{
this.enabled = false;
}
}
ЭТО ВТОРОЙ СКРИПТ В НЕГО НУЖНО ВЫЗВАТЬ КЛАСС (STOP)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public Rigidbody2D rb;
public Vector2 moveVector;
public float speed = 3.5f;
public float jumpForce = 6f;
public Animator anim;
public SpriteRenderer sr;
public bool onGround;
public Transform GroundCheck;
public float checkRadius = 0.5f;
public LayerMask Ground;
public static Player Instance { get; set; }
[SerializeField] private int lives = 5;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
sr = GetComponent<SpriteRenderer>();
Instance = this;
}
void Update()
{
Walk();
Jump();
Flip();
CheckingGround();
}
//ХОДЬБА
void Walk()
{
moveVector.x = Input.GetAxis("Horizontal");
anim.SetFloat("MoveX" , Mathf.Abs(moveVector.x));
rb.velocity = new Vector2(moveVector.x * speed, rb.velocity.y);
}
//ПРИЖОК
void Jump()
{
if(Input.GetKeyDown(KeyCode.Space) && onGround)
{
rb.velocity = new Vector2 (rb.velocity.x, jumpForce);
}
}
void Flip()
{
if(moveVector.x > 0)
{
sr.flipX = false;
}
else if (moveVector.x < 0)
{
sr.flipX = true;
}
}
void CheckingGround()
{
onGround = Physics2D.OverlapCircle(GroundCheck.position, checkRadius, Ground);
anim.SetBool("onGround", onGround);
}
public void GetDamage()
{
lives -=1;
Debug.Log(lives);
}
void Stoper()
{
if(moveVector.x > 0)
{
Stop();
}
}
}