using System.Collections; using System.Collections.Generic; using UnityEngine; public class Schillage_Austin_3 : MonoBehaviour { // Start is called before the first frame update void Start() { } public float speed = 3; // Update is called once per frame void Update() { Movement(); Rotation(); Shooting(); } public GameObject laser; public float timeBetweenShots = 0.5f; private float nextShotTime; void Shooting() { bool canShoot = Time.time > nextShotTime; if (Input.GetButton("Fire1") && canShoot) { Instantiate(laser, transform.position, transform.rotation); nextShotTime = Time.time + timeBetweenShots; } } void Rotation() { Vector3 mousePos = Input.mousePosition; Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos); //print("Screen : " + mousePos + " World " + worldPos); Vector2 delta = transform.position - worldPos; //get the angle between 2 objects float angle = Mathf.Atan2(delta.y, delta.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0, 0, angle + 90); } void Movement() { float xMove = Input.GetAxis("Horizontal"); float yMove = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(xMove, yMove); // slows down movement *= Time.deltaTime * speed; transform.position += movement; } }