Search Unity

PLEASE HELP ME WHY IT IS NOT DRAWING LINE

Discussion in 'Editor & General Support' started by fatihsariopk, Aug 25, 2019.

  1. fatihsariopk

    fatihsariopk

    Joined:
    Aug 25, 2019
    Posts:
    3
    public class BombaciKontrol : MonoBehaviour
    {
    private Vector3 uretilenNokta;
    private Vector3 pozisyon;
    private Vector3 noktaVeDusmanArasiFark;
    private float randomX = 0, randomY = 0;
    private float mesafe = 0;
    private float beklemeZamani = 0;
    private float beklemeRandom = 0;
    private GameObject noktaObjesi;
    private DusmanDurum durum = DusmanDurum.NoktaBulamadi;
    private RaycastHit2D noktayaRay;
    [SerializeField] LayerMask layerMask;
    Rigidbody2D fizik;

    public LayerMask LayerMask { get => layerMask; set => layerMask = value; }

    void Start()
    {
    uretilenNokta = new Vector3();
    noktaVeDusmanArasiFark = new Vector3();
    noktaObjesi = new GameObject("BombacininGidecegiNokta");
    CircleCollider2D col = noktaObjesi.AddComponent<CircleCollider2D>();
    col.isTrigger = true;
    col.radius = 0.15f;
    fizik = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
    NoktaBul();
    DusmanHareketi();
    }

    private void OnDrawGizmos()
    {
    Gizmos.color = Color.red;
    Gizmos.DrawWireSphere(uretilenNokta, 0.5f);
    }

    private void NoktaBul()
    {
    if (durum == DusmanDurum.NoktaBulamadi)
    {
    pozisyon = transform.position;
    randomX = Random.Range(2, 7);
    randomY = Random.Range(2, 7);
    uretilenNokta.Set(pozisyon.x + Random.Range(randomX * -1, randomX), pozisyon.y + Random.Range(randomY * -1, randomY), 0);
    noktaObjesi.transform.position = uretilenNokta;
    NoktayaRayCizdir();
    }

    }

    private void NoktayaRayCizdir()
    {
    noktaVeDusmanArasiFark = (uretilenNokta - transform.position).normalized;
    noktayaRay = Physics2D.Raycast(transform.position, noktaVeDusmanArasiFark, 1000, layerMask);
    Debug.DrawLine(transform.position, noktayaRay.point);
    if (noktayaRay && noktayaRay.collider.name == noktaObjesi.name)
    {
    durum = DusmanDurum.NoktaBuldu;
    }
    }

    private void DusmanHareketi()
    {
    if (durum == DusmanDurum.KarakterGordu)
    {

    }
    else
    {
    if (durum == DusmanDurum.NoktaBuldu)
    {
    fizik.position += (Vector2)(uretilenNokta - transform.position).normalized;
    mesafe = Vector3.Distance(transform.position, noktayaRay.point);
    if (mesafe < 0.01f)
    {
    durum = DusmanDurum.Bekle;
    beklemeRandom = Random.Range(0.2f, 2.0f);
    }
    }
    else if (durum == DusmanDurum.Bekle)
    {
    beklemeZamani += Time.fixedDeltaTime;
    if (beklemeZamani>beklemeRandom)
    {
    durum = DusmanDurum.NoktaBulamadi;
    beklemeZamani = 0;
    }
    }
    }
    }
    }


    public enum DusmanDurum
    {
    NoktaBuldu = 1,
    NoktaBulamadi = 2,
    Bekle = 3,
    KarakterGordu = 4
    } 2019-08-23_11-51-58-3e27b0a7f3ad60f4884b801a941636d0 (1).png 2019-08-23_11-51-58-a30326594b907885a576d4a7a9669e5e.png 2019-08-23_11-51-58-cabf4ae4bd0165710f289cd21ea88c85.png 2019-08-23_11-51-58-3e27b0a7f3ad60f4884b801a941636d0 (1).png 2019-08-23_11-51-58-a30326594b907885a576d4a7a9669e5e.png 2019-08-23_11-51-58-cabf4ae4bd0165710f289cd21ea88c85.png
     

    Attached Files:

  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Are you looking for the line in the Scene View, or the Game View? It hard to follow your code, since you didn't use Code tags, and it's full of language I don't understand, but you're only use Debug.DrawLine and Gizmos to draw lines. Those will only show up in the Scene View, and you won't see them when actually playing the game.
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    toggle Gizmos on to see debug lines in gameview,
    upload_2019-8-26_9-47-59.png
    (but they wont be visible in build, only in editor)
     
  4. fatihsariopk

    fatihsariopk

    Joined:
    Aug 25, 2019
    Posts:
    3
    I WANT ON SCENE VİEW. LOOK AT RED PLAYER. IT HAS A LINE BUT BLUE ONE HASN'T GOT A LINE. BUT I WROTE A SCRIPT ABOUT IT.
     
  5. fatihsariopk

    fatihsariopk

    Joined:
    Aug 25, 2019
    Posts:
    3
    PLEASE HELP GUYS. I've been trying to fix this for 2 days
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Both of the players have the BombaciKontrol script on them?

    Is "durum == DusmanDurum.NoktaBulamadi" true for both players?

    Anyway, your code is hard for me to follow because of the language difference, but you should simplify things to understand what's failing. Put Debug.Log statements in your code to see which lines of code are being reached, or attach the debugger and step through the Update method to see what's not true.
     
    Joe-Censored and Thimble2600 like this.