using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class controlDog : MonoBehaviour
{
[SerializeField] private float moveSpeed;
[SerializeField] private float leftLimit;
[SerializeField] private float rightLimit;
[SerializeField] private float forwardLimit;
[SerializeField] private float backwardLimit;
private GameObject carriedBall;
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
// Calculate the movement direction
Vector3 moveDirection
= new Vector3
(horizontalInput, 0f, verticalInput
);
// Check if there is any input
if (moveDirection != Vector3.zero)
{
// Rotate the dog to face the movement direction
transform.LookAt(transform.position + moveDirection);
}
// Move the dog in the facing direction
transform.Translate(moveDirection.normalized * moveSpeed * Time.deltaTime, Space.World);
// Limit the position to the specified range
LimitPosition();
}
void LimitPosition()
{
// Limit the position in the X-axis
transform
.position = new Vector3
(
Mathf.Clamp(transform.position.x, leftLimit, rightLimit),
transform.position.y,
transform.position.z
);
// Limit the position in the Z-axis
transform
.position = new Vector3
(
transform.position.x,
transform.position.y,
Mathf.Clamp(transform.position.z, backwardLimit, forwardLimit)
);
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}