En este momento estás viendo No puedo ver la bala en la ventana del juego. unity 2d

 – Unity

No puedo ver la bala en la ventana del juego. unity 2d – Unity

No puedo ver la bala en la ventana del juego. unity 2d

– UnityAssets3Free

bienvenido , por aqui Daniel y aqui os traigo
nueva pregunta curiosa

Seguí un tutorial para disparar balas en unity 2D y traté de implementarlo. La bala simplemente no aparece. Puedo verlo en la ventana Escena, pero no en la ventana Juego. Tengo un jugador con RigidBody2D y BoxCollider2D, como hijo del jugador tengo un hijo RotatePoint vacío y como hijo de eso tengo un hijo BulletTransform vacío con un renderizador de sprites. RotatePoint tiene un script llamado Shooting. También tengo un prefabricado llamado Bullet en los archivos del proyecto, que es un objeto vacío con un renderizador de sprites, un rigidbody2d y un script llamado BulletScript

aquí está el tutorial que seguí si ayuda: https://www.youtube.com/watch?v=-bkmPm_Besk

código para Shooting:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class shooting : MonoBehaviour

    private Camera mainCam;
    private Vector3 mousePos;
    public GameObject bullet;
    public Transform bulletTransform;
    public bool canFire;
    private float timer;
    public float timeBetweenFiring;
    // Start is called before the first frame update
    void Start()
    
        mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
    

    // Update is called once per frame
    void Update()
    
        mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);

        Vector3 rotation = mousePos -  transform.position;

        float rotZ = Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg;

        transform.rotation = Quaternion.Euler(0, 0, rotZ);

        if (!canFire)
        
            timer += Time.deltaTime;
            if (timer> timeBetweenFiring)
            
                canFire = true;
                timer = 0;
            
        

        if(Input.GetMouseButton(0) && canFire)
        
            canFire = false;
            Instantiate(bullet, bulletTransform.position, Quaternion.identity); 

        


    


código para BulletScript:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletScript : MonoBehaviour

    private Vector3 mousePos;
    private Camera mainCam;
    private Rigidbody2D rb;
    public float force;
    // Start is called before the first frame update
    void Start()
    
        mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
        rb = GetComponent<Rigidbody2D>();
        mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);
        Vector3 direction = mousePos - transform.position;
        Vector3 rotation = transform.position = mousePos;
        rb.velocity = new Vector2(direction.x, direction.y).normalized * force;
        float rot = Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.Euler(0, 0, rot + 90);

    

    // Update is called once per frame
    void Update()
    
        
    


0

nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias

sin mas,hasta la proxima

Deja una respuesta