So, i 3 hours trying to make a shooting weapon. Its spawn on weapon, but not moving.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Bulletshoot : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var x = GameObject.Find("weapon").transform.position.x;
var y = GameObject.Find("weapon").transform.position.y;
KeyCode RightKey = KeyCode.Space;
if (Input.GetKey(RightKey))
{
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Debug.Log("got it");
var spedx = mousePosition.x - transform.position.x;
var spedy = mousePosition.y - transform.position.y;
Console.WriteLine("Ok, bullet remaind");
transform.position = GameObject.Find("weapon").transform.position;
transform.rotation = GameObject.Find("weapon").transform.rotation;
transform.Rotate(Vector3.forward * -90);
GetComponent().AddForce(Vector3.forward, ForceMode2D.Impulse);
Debug.Log("got it");
}
}
}
↧