Skip to content

Instantly share code, notes, and snippets.

@yjsoon
Last active April 7, 2017 09:50
Show Gist options
  • Save yjsoon/d9b7b0a9ac8fff336ff04b3fb353c7b0 to your computer and use it in GitHub Desktop.
Save yjsoon/d9b7b0a9ac8fff336ff04b3fb353c7b0 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShooterScript : MonoBehaviour {
public Transform bulletTransform;
public Rigidbody bulletTemplate;
public float bulletSpeedX = -1000.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown ("Fire1")) {
GenerateBullet ();
}
if (Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.UpArrow)) {
transform.position = transform.position + new Vector3 (0, 0.1f, 0);
}
if (Input.GetKey (KeyCode.S) || Input.GetKey (KeyCode.DownArrow)) {
transform.position = transform.position + new Vector3 (0, -0.1f, 0);
}
}
void GenerateBullet() {
Quaternion rot = transform.rotation;
Rigidbody generatedBall = (Rigidbody)Instantiate (bulletTemplate, bulletTransform.position, rot);
generatedBall.AddForce (new Vector3 (bulletSpeedX, 0, 0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment