Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour
- {
- [SerializeField] float playerSpeed = 1f;
- public Rigidbody2D rb;
- public Camera cam;
- Vector3 mousePos;
- public Animator animator;
- [SerializeField] GameObject fireballPrefab;
- private void Start()
- {
- rb = this.GetComponent<Rigidbody2D>();
- }
- void Update()
- {
- movement();
- if (Input.GetButtonDown("Fire1"))
- {
- fire();
- }
- }
- public void fire()
- {
- GameObject bullet = Instantiate(fireballPrefab, Transform.Position, Quaternion.identity);
- }
- public void movement()
- {
- Vector3 mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
- if (mousePos.x < rb.position.x)
- {
- transform.localScale = new Vector3(-1, 1, 1);
- }
- if (mousePos.x > rb.position.x)
- {
- transform.localScale = new Vector3(1, 1, 1);
- }
- animator.SetFloat("speed", mousePos.z);
- if (Input.GetKey(KeyCode.W))
- {
- mousePos.z = transform.position.z;
- transform.position = Vector3.MoveTowards(transform.position, mousePos, playerSpeed * Time.deltaTime);
- animator.SetFloat("speed", mousePos.x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement