Newer
Older
HardPoint-Project-Abertay-University-Unity3D / Assets / Content / Developers / Miguel / MiguelToys / Shoot.cs
@Rackday Rackday on 18 Aug 623 bytes Project Added
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shoot : MonoBehaviour
{
    [SerializeField]
    private GameObject bullet;

    private Rigidbody rb;


    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    public void Attack()
    {
        Vector3 dir = Vector3.Normalize(Input.mousePosition - new Vector3(Screen.width / 2, Screen.height / 2, 0));
        GameObject temp = Instantiate(bullet,transform.position + (dir * 2), Quaternion.identity);
        temp.GetComponent<Rigidbody>().velocity = dir * 30;
        rb.velocity += -dir * 30;
    }
}