0% found this document useful (0 votes)
20 views1 page

Public Class Public Float Public Float Public Float Public: Using Using Using

This C# script controls the movement and firing of a player character in a Unity game. It gets horizontal input to move the player object from side to side within a limited range at a set speed over time. It also instantiates a projectile prefab when the space bar is pressed, using the player's position and rotation.

Uploaded by

Irving Palma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Public Class Public Float Public Float Public Float Public: Using Using Using

This C# script controls the movement and firing of a player character in a Unity game. It gets horizontal input to move the player object from side to side within a limited range at a set speed over time. It also instantiates a projectile prefab when the space bar is pressed, using the player's position and rotation.

Uploaded by

Irving Palma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System.

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

public class PlayerController : MonoBehaviour {
    public float horizontalImput;
    public float speed = 10;
    public float xRange = 15.0f;
    public GameObject projectilPrefab;

    // Update is called once per frame
    void Update() {
        horizontalImput = Input.GetAxis("Horizontal");
        transform.Translate(Time.deltaTime * speed * Vector3.right * hori
zontalImput);

        if (transform.position.x < -xRange) {
            transform.position = new Vector3(-xRange, transfor
m.position.y, transform.position.z);
        }
        if (transform.position.x > xRange) {
            transform.position = new Vector3(xRange, transform.position.y
, transform.position.z);
        }

        if (Input.GetKeyDown(KeyCode.Space)) {
            Instantiate(projectilPrefab, transform.position, projectilPre
fab.transform.rotation);
        }
    }
}

You might also like