I Can't get values from variable(Vector2).
My goal is send float variable from PlayerAttack to PlayerAttacking.
public class PlayerAttack : MonoBehaviour
{
[Header("Components")]
[SerializeField]
private Rigidbody2D _Player_Rigidbody;
[SerializeField]
private Camera _Main_Camera;
public Transform target;
public Vector2 offset = Vector2.zero;
private PlayerState CurrentPlayerState;
void Start()
{
}
void Update()
{
Vector3 Mouse = Input.mousePosition;
Vector3 ScreenPoint = _Main_Camera.WorldToScreenPoint(target.localPosition);
// Offset - help you realize 4 ways attack system
offset = new Vector2(Mouse.x - ScreenPoint.x, Mouse.y - ScreenPoint.y);
Debug.Log("PlayerAttack Log: " + offset.ToString());
FindPlayerState(CurrentPlayerState);
if(VirtualInputManager.Instance.Attack && CurrentPlayerState.ToString() != aro_game.PlayerState.attack.ToString())
{
StartCoroutine(AttackCo());
//Debug.Log("Virtual Input Manager said true and Current state doesnt equal attack");
Debug.Log("ATTACK LOGIC");
}
}
public PlayerState FindPlayerState(PlayerState temp_state)
{
GameObject Object = GameObject.Find("Player");
PlayerMovement PlayerState = Object.GetComponent<PlayerMovement>();
temp_state = PlayerState.CurrentPlayerState;
return temp_state;
}
private IEnumerator AttackCo()
{
CurrentPlayerState = PlayerState.attack;
yield return new WaitForSeconds(0.65f);
CurrentPlayerState = PlayerState.idle;
}
}
then I created a method to get values from this variable.(This is CharacterState code):
protected void FindAttackAngle(Vector2 temp_angle)
{
GameObject Object = GameObject.Find("Player");
PlayerAttack attackangle = Object.GetComponent<PlayerAttack>();
temp_angle = attackangle.offset;
Debug.Log("CharacterState Log: " + temp_angle.ToString());
}
And if attack animation starts the PlayerAttacking script inherited from CharacterState must start, too.
public class PlayerAttacking : CharacterState
{
private PlayerState _state;
private Vector2 _attackangle = Vector2.zero;
public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
{
FindAttackAngle(_attackangle);
Debug.Log("PlayerAttackingAnimation Log:" + _attackangle.ToString());
CheckPlayerState(_state);
if (_state != PlayerState.attack)
{
// Front attack
//Debug.Log(_attackangle.ToString());
if ((_attackangle.x < 1f && _attackangle.y < 1f) && (_attackangle.x > -1 && _attackangle.y > 1))
{
Debug.Log("FRONT ATTACK");
animator.SetBool("!Attack", true);
}
//Back attack
if ((_attackangle.x > -1f && _attackangle.y > -1f) && (_attackangle.x < 1 && _attackangle.y < -1f))
{
Debug.Log("BACK ATTACK");
animator.SetBool("!Attack", true);
}
//Left attack
if ((_attackangle.x < -1f && _attackangle.y < -1f) && (_attackangle.x > -1f && _attackangle.y > 1f))
{
Debug.Log("LEFT ATTACK");
animator.SetBool("!Attack", true);
}
//Right attack
if ((_attackangle.x > 1f && _attackangle.y > -1f) && (_attackangle.x < 1f && _attackangle.y < 1f))
{
Debug.Log("RIGHT ATTACK");
animator.SetBool("!Attack", true);
}
}
}
public override void OnStateUpdate(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
{
}
public override void OnStateExit(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
{
animator.SetBool("!Attack", false);
animator.SetBool("Attack", false);
}
}
You can see the Debug Log here .
Why is the last Log equal to 0:0? And how can I change this value if the issue is not happening due to an error in my code?
If you need more details, ask your questions in the comments section pleas.