public float firstDir = 1.0f; // プレイヤーの向いている方向 // ====== コード(Monobehaviour基本機能の実装) ========= void Awake() { cam = Camera.main; player = GameObject.FindGameObjectWithTag("Player"). GetComponent <PlayerRB>(); playerTrfm = GameObject.FindGameObjectWithTag("Player").transform; }
void Attack() { if (!isAttacking) { if (!attackOnCooldown) { if (Input.GetKeyDown(KeyCode.X)) { IsAttacking = true; AttackDurationCountdown = attackDuration; StartCoroutine("HitScan", lanceHitBox); } } else { AttackCooldownCountdown -= Time.deltaTime; if (AttackCooldownCountdown <= 0) { AttackOnCooldown = false; } } } //If Player Attacking if (isAttacking) { int dirX = 0; attackCountdownDuration -= Time.deltaTime; if (attackCountdownDuration >= 0) { PlayerRB.drag = 1f; PlayerRB.gravityScale = .3f; CanMove = false; if (playerDirection.Equals(Direction.LEFT)) { dirX = -1; } else { dirX = 1; } Vector2 force = new Vector2(dirX * attackForce, 0); PlayerRB.AddForce(force); } else { PlayerRB.gravityScale = 1f; IsAttacking = false; AttackOnCooldown = true; AttackCooldownCountdown = attackCooldownDuration; StopCoroutine("HitScan"); CanMove = true; } } }
void OnTriggerStay2D(Collider2D ColliderPlayer) { if (ColliderPlayer.CompareTag("Player") && punchCD <= 0) { PlayerRB = ColliderPlayer.GetComponent <Rigidbody2D>(); ColliderPlayer.GetComponent <Player_Controller>().TakeDamage(AttackDamage); VecDif = EnemyObject.transform.position - ColliderPlayer.transform.position; PlayerRB.AddForce(VecDif.normalized * PunchForce * -1); ColliderPlayer.GetComponent <DamageIndicator>().Damaged(); punchCD = 1; } }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player"). GetComponent <PlayerRB>(); }