Answers for "player controls for top down game script"

1

player controls for top down game script

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Security.Cryptography;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 20.0f;
    public float horizontalInput;
    public flaot xRange = 30;
    
    public GameObject projectilePreFab;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if  (transform.position.x < -xRange)
         {
            transform.position = new Vector3(xRange, transform.position.y, transform.position.z);
         }
        if  (transform.position.x > xRange)
         {
            transform.position = new Vector3(xRange, transform.position.y, transform.position.z)
         }
          horizontalInput = Input.GetAxis("Horizontal")
          transform.Translate(Vector3.right * Time.deltaTime * speed * horizontalInput);
         if (Input.GetKeyDown(KeyCode.Space))
         {
            Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.Rotation);
         }
    }
}
Posted by: Guest on July-21-2021

Browse Popular Code Answers by Language