(1)ボタンを「押した時」にボールがジャンプする
(サンプルコード)
using UnityEngine;
public class BallJump : MonoBehaviour
{
private float power = 5;
private Rigidbody rb;
private bool isJumping = false;
private InputSystem_Actions isa;
void Start()
{
rb = this.gameObject.AddComponent<Rigidbody>();
isa = new InputSystem_Actions();
isa.Enable();
}
void Update()
{
// ★インプットシステム
// ボタンを押した時
if(isa.Player.Jump.triggered)
{
rb.linearVelocity = Vector3.up * power;
}
}
private void OnDisable()
{
isa.Disable();
}
}
*スペースキーを押した時、ボールがジャンプすれば成功
(2)ボタンを「押している時」にボールがジャンプする
(サンプルコード)
using UnityEngine;
public class BallJump : MonoBehaviour
{
private float power = 2;
private Rigidbody rb;
private InputSystem_Actions isa;
void Start()
{
rb = this.gameObject.AddComponent<Rigidbody>();
isa = new InputSystem_Actions();
isa.Enable();
}
void Update()
{
// ★インプットシステム
// ボタンを押している時
if(isa.Player.Jump.IsPressed())
{
rb.linearVelocity = Vector3.up * power;
}
}
private void OnDisable()
{
isa.Disable();
}
}
*スペースキーを押している間、ボールが上昇すれば成功
(3)ボタンを「離した」にボールがジャンプする
(サンプルコード)
using UnityEngine;
public class BallJump : MonoBehaviour
{
private float power = 7;
private Rigidbody rb;
private InputSystem_Actions isa;
void Start()
{
rb = this.gameObject.AddComponent<Rigidbody>();
isa = new InputSystem_Actions();
isa.Enable();
}
void Update()
{
// ★インプットシステム
// ボタンから指を離した時
if(isa.Player.Jump.WasReleasedThisFrame())
{
rb.linearVelocity = Vector3.up * power;
}
}
private void OnDisable()
{
isa.Disable();
}
}
*スペースキーを押して離した瞬間にジャンプすれば成功