Skip to content

Instantly share code, notes, and snippets.

@r-wheeler
Created September 28, 2016 20:46
Show Gist options
  • Save r-wheeler/d7c1def12b3394eb9f8f71dfbedd91e0 to your computer and use it in GitHub Desktop.
Save r-wheeler/d7c1def12b3394eb9f8f71dfbedd91e0 to your computer and use it in GitHub Desktop.
Break a wall
using UnityEngine;
using System.Collections;
public class Shooter : MonoBehaviour {
public Rigidbody bullet;
public float power = 1500f;
public float moveSpeed = 2f;
// Update is called once per frame
void Update () {
float h = Input.GetAxis("Horizontal") * Time.deltaTime *
moveSpeed;
float v = Input.GetAxis("Vertical") * Time.deltaTime *
moveSpeed;
//The transofrm attached to the game object
//This is the camera because we dropped it onto the main cam
transform.Translate(h,v,0);
if (Input.GetButtonUp("Fire1")){
Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation)
as Rigidbody;
//Create an instance of a 3d vector facing the sam direction as cam
Vector3 fwd = transform.TransformDirection(Vector3.forward);
instance.AddForce(fwd * power);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment