Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Shooter : MonoBehaviour {
  6.  
  7. public Rigidbody bullet;
  8. public float power = 1500f;
  9. public float moveSpeed = 2f;
  10.  
  11. void Start () {
  12.  
  13. }
  14.  
  15. // Update is called once per frame
  16. void Update ()
  17. {
  18. float h = Input.GetAxis("Horizontal")*Time.deltaTime*moveSpeed;
  19. float v = Input.GetAxis("Vertical")*Time.deltaTime*moveSpeed;
  20. transform.Translate(h,v,0);
  21.  
  22. if (Input.GetButtonUp("Fire1"))
  23. {
  24. Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
  25.  
  26. Vector3 fwd = transform.TransformDirection(Vector3.forward);
  27. instance.AddForce(fwd*power);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement