[text] d

Viewer

  1. using UnityEngine;
  2.  
  3. public class GerakPemukul : MonoBehaviour
  4. {
  5.     public float batasAtas;
  6.     public float batasBawah;
  7.     public float kecepatan;
  8.     public string axis;
  9.     // Start is called before the first frame update
  10.     void Start()
  11.     {
  12.         
  13.     }
  14.  
  15.     // Update is called once per frame
  16.     void Update()
  17.     {
  18.         float gerak = Input.GetAxis(axis) * kecepatan * Time.deltaTime;
  19.         float nextPos = transform.position.y + gerak;
  20.         if (nextPos > batasAtas)
  21.         {
  22.             gerak = 0;
  23.         }
  24.         if (nextPos < batasBawah)
  25.         {
  26.             gerak = 0;
  27.         }
  28.         transform.Translate(0, gerak, 0);
  29.     }
  30. }
  31.  

Editor

You can edit this paste and save as new:


File Description
  • d
  • Paste Code
  • 29 Apr-2024
  • 687 Bytes
You can Share it: