34 lines
886 B
C#
34 lines
886 B
C#
|
|
using UnityEngine;
|
|
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
public float Speed = 1;
|
|
public float Limit =7;
|
|
public GameObject BulletPrefab;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
transform.Translate(new Vector2 (Input.GetAxis("Horizontal") * Speed * Time.deltaTime,0));
|
|
if(transform.position.x <-Limit)
|
|
{
|
|
transform.position = new Vector3(-Limit,transform.position.y,0);
|
|
}
|
|
if(transform.position.x >Limit)
|
|
{
|
|
transform.position =new Vector3( Limit,transform.position.y,0);
|
|
}
|
|
|
|
if(Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
Instantiate(BulletPrefab,transform.position,Quaternion.identity);
|
|
}
|
|
}
|
|
}
|