C
C#5d ago
moonbat

Is there a way to make this a shorter phrase.

I was wondering if i was able to put both input under the same name. something like
if(cheeseburger){jump}
if(cheeseburger){jump}
, rather than this
using System.Linq.Expressions;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class Playerjump : MonoBehaviour
{
[SerializeField] private float _velocity = 1.5f;
private Rigidbody2D _rb;

// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame)
{
_rb.linearVelocity = Vector2.up * _velocity;
}

if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
_rb.linearVelocity = Vector2.up * _velocity;
}
}
}
using System.Linq.Expressions;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class Playerjump : MonoBehaviour
{
[SerializeField] private float _velocity = 1.5f;
private Rigidbody2D _rb;

// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame)
{
_rb.linearVelocity = Vector2.up * _velocity;
}

if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
_rb.linearVelocity = Vector2.up * _velocity;
}
}
}
3 Replies
leowest
leowest5d ago
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame ||
Keyboard.current.spaceKey.wasPressedThisFrame)
{
_rb.linearVelocity = Vector2.up * _velocity;
}
}
void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame ||
Keyboard.current.spaceKey.wasPressedThisFrame)
{
_rb.linearVelocity = Vector2.up * _velocity;
}
}
if this is true or that is true do this
ero
ero5d ago
i have to wonder why this isn't using Input.GetKeyDown, or Input.GetButton, or the new InputSystem recommend looking into at least the last of the few
moonbat
moonbatOP5d ago
Tyvm

Did you find this page helpful?