warasadi / RPL-2

0 stars 0 forks source link

KUMPULAN SKRIP #2

Open warasadi opened 1 year ago

warasadi commented 1 year ago

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class putar : MonoBehaviour { public float rotationSpeed = 100.0f; // Kecepatan putaran koin (sesuaikan sesuai kebutuhan)

// Update is called once per frame
void Update()
{
    // Mengatur putaran koin di sekitar sumbu Y
    transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
}

}

warasadi commented 1 year ago

using UnityEngine;

public class CubeMovement : MonoBehaviour { public float moveSpeed = 5.0f;

void Update()
{
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput) * moveSpeed * Time.deltaTime;

    transform.Translate(movement);

    // Batasi pergerakan kubus agar tidak keluar dari batas tertentu
    float xBound = 5.0f; // Gantilah dengan batas sesuai kebutuhan
    float zBound = 5.0f; // Gantilah dengan batas sesuai kebutuhan

    Vector3 currentPosition = transform.position;
    currentPosition.x = Mathf.Clamp(currentPosition.x, -xBound, xBound);
    currentPosition.z = Mathf.Clamp(currentPosition.z, -zBound, zBound);

    transform.position = currentPosition;
}

}

warasadi commented 1 year ago

https://drive.google.com/drive/folders/1_yDjvbVbjA8p2JHMnikURhTmOCVlYAMa?usp=drive_link