Olá alguém poderia me ajudar?

I’m trying to make my player with it only project go to all tasks, but it goes to the left, here the project Script can only be done:

using UnityEngine;

public class BulletRed : MonoBehaviour
{
    const float lifeTime = 1;
    public float speed;

    // Start is called before the first frame update
    void Start()
    {
        Destroy(this.gameObject, lifeTime);
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector2.left * speed * Time.deltaTime);
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag.Equals("Player"))
        {
            return;
        }
        if (collision.gameObject.tag.Equals("Player2"))
        {
            var Player2Obj = collision.GetComponent<VidaAzul>();
            Player2Obj.TomaDano(1);
        }
        Destroy(gameObject);
    }



}

Here’s the Player:

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

public class Player1 : MonoBehaviour
{
    public Animator anim;
    public float speed;

    public GameObject ProgetelV;

    // Update is called once per frame
    void Update()
    {
        Shoot();

        Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);

        anim.SetFloat("Horizontal", movement.x);
        anim.SetFloat("Vertical", movement.y);
        anim.SetFloat("Speed", movement.magnitude);

        transform.position = transform.position + movement * speed * Time.deltaTime;
    }

    void Shoot()
    {
        if (Input.GetKeyDown(KeyCode.E))
            Instantiate(ProgetelV, this.transform.position, this.transform.rotation);
    }
}

Does anyone know how to solve it?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

You can edit your post above to fix the formatting.

Translated for English forum:

I’m trying to make my player’s projectile go in all directions, but it only goes to the left, here’s the projectile’s script:

Answer:

You must find a way to get the information you need in order to reason about what the problem is.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also put in Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

https://discussions.unity.com/t/839300/3

1 Like

Post in English please, no disrespect but you’re creating more work for people to help you, please make it easier for people to help you. The forums are English only.

1 Like

Thank you for updating to English, greatly appreciated.

1 Like