Advertisement
Guest User

Untitled

a guest
Jan 16th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class basicMouseController : MonoBehaviour {
  5. public float moveSpeed;
  6. private Vector3 moveDirection;
  7. public float turnSpeed;
  8. public Rigidbody2D bullet;
  9. public float bulletSpeed;
  10. private float lastShot = 0;
  11. public float fireRate;
  12. // Use this for initialization
  13. void Start () {
  14. moveDirection = Vector3.right;
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update () {
  19.  
  20. // 1
  21. Vector3 currentPosition = transform.position;
  22. // 2
  23. if( Input.GetButton("Fire1") ) {
  24. // 3
  25. Vector3 moveToward = Camera.main.ScreenToWorldPoint( Input.mousePosition );
  26. // 4
  27. moveDirection = moveToward - currentPosition;
  28. moveDirection.z = 0;
  29. moveDirection.Normalize();
  30. }
  31. Vector3 target = moveDirection * moveSpeed + currentPosition;
  32. transform.position = Vector3.Lerp( currentPosition, target, Time.deltaTime );
  33. float targetAngle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
  34. transform.rotation =
  35. Quaternion.Slerp( transform.rotation,
  36. Quaternion.Euler( 0, 0, targetAngle ),
  37. turnSpeed * Time.deltaTime );
  38.  
  39. if (Input.GetButtonDown ("Jump")) {
  40. print ("fire");
  41. Rigidbody2D cloneBullet;
  42. cloneBullet = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody2D;
  43. cloneBullet.velocity = moveDirection * bulletSpeed;
  44. /*if (Time.time > fireRate + lastShot)
  45. {
  46. cloneBullet = Instantiate( bullet, pistol.transform.position, pistol.transform.rotation);
  47. lastShot = Time.time;
  48. bulletsFired++;
  49. } */
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement