Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackingMechanic : MonoBehaviour
{
[SerializeField] private Transform attackTransform; // These just refuse to show up in the editor for whatever reason.
[SerializeField] private float attackRange = 1.5f;
[SerializeField] private LayerMask attackableLayer;
[SerializeField] private float damageAmount = 1f;
private RaycastHit2D[] hits;
private void Update()
{
if (UserInput.instance.Controls.Attack.Attack.WasPressedThisFrame()) // error CS1061
{
// attack
}
}
private void Attack()
{
hits = Physics2D.CircleCastAll(attackTransform.position, attackRange, transform.right, 0f, attackableLayer);
for (int i = 0; i < hits.Length; i++)
{
IDamageable iDamgageable = hits[i].collider.gameObject.GetComponent();
// if we found a Damageable
if (iDamgageable != null)
{
// apply damage
iDamgageable.Damage(damageAmount);
}
}
}
private void OnDrawGizmosSelected()
{
Gizmos.DrawWireSphere(attackTransform.position, attackRange);
}
}
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserInput : MonoBehaviour
{
public static UserInput instance;
[HideInInspector] public Controls controls;
private void Awake()
{
if (instance == null)
{
instance = this;
}
controls = new Controls();
}
private void OnEnable()
{
Controls.Enable(); // error CS0120
}
private static void OnDisable()
{
Controls.Disable(); // error CS0120
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... or-c-sharp
Мобильная версия