Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class BulletBehavior : MonoBehaviour {
- private float speed = 5f;
- public float rotationSpeed;
- private Transform myTrans;
- private Vector3 myPos, myRot;
- private float angle;
- void Start (){
- myTrans = transform;
- myPos = myTrans.position;
- myRot = myTrans.rotation.eulerAngles;
- }
- void FixedUpdate () {
- angle = myTrans.eulerAngles.magnitude * Mathf.Deg2Rad;
- if (Input.GetKey (KeyCode.RightArrow)) {
- myRot.z -= rotationSpeed;
- }
- if (Input.GetKey (KeyCode.LeftArrow)) {
- myRot.z += rotationSpeed;
- }
- if (Input.GetKey (KeyCode.UpArrow)) {
- myPos.x += (Mathf.Cos (angle) * speed) * Time.deltaTime;
- myPos.y += (Mathf.Sin (angle) * speed) * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.DownArrow)) {
- myPos.x += Mathf.Cos (angle) * Time.deltaTime;
- myPos.y += Mathf.Sin (angle) * Time.deltaTime;
- }
- myTrans.position = myPos;
- myTrans.rotation = Quaternion.Euler (myRot);
- }
- }
Add Comment
Please, Sign In to add comment