Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class basicMouseController : MonoBehaviour {
- public float moveSpeed;
- private Vector3 moveDirection;
- public float turnSpeed;
- public Rigidbody2D bullet;
- public float bulletSpeed;
- private float lastShot = 0;
- public float fireRate;
- // Use this for initialization
- void Start () {
- moveDirection = Vector3.right;
- }
- // Update is called once per frame
- void Update () {
- // 1
- Vector3 currentPosition = transform.position;
- // 2
- if( Input.GetButton("Fire1") ) {
- // 3
- Vector3 moveToward = Camera.main.ScreenToWorldPoint( Input.mousePosition );
- // 4
- moveDirection = moveToward - currentPosition;
- moveDirection.z = 0;
- moveDirection.Normalize();
- }
- Vector3 target = moveDirection * moveSpeed + currentPosition;
- transform.position = Vector3.Lerp( currentPosition, target, Time.deltaTime );
- float targetAngle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
- transform.rotation =
- Quaternion.Slerp( transform.rotation,
- Quaternion.Euler( 0, 0, targetAngle ),
- turnSpeed * Time.deltaTime );
- if (Input.GetButtonDown ("Jump")) {
- print ("fire");
- Rigidbody2D cloneBullet;
- cloneBullet = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody2D;
- cloneBullet.velocity = moveDirection * bulletSpeed;
- /*if (Time.time > fireRate + lastShot)
- {
- cloneBullet = Instantiate( bullet, pistol.transform.position, pistol.transform.rotation);
- lastShot = Time.time;
- bulletsFired++;
- } */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement