Şimdi Ara

Unity 2D Düşman Okçusu Yapılması

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
3
Cevap
0
Favori
358
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhaba arkadaşlar, düşman okçusu yapmak istiyorum. Fakat şöyle bir sorun var. Yaptığım okçu sürekli aynı yere ateş ediyor. Player'ın son pozisyonuna ateş etmesini istiyorum. Playerin son pozisyonu için "public Transform PlayerPosition" ekledim ama nasıl kullanılacağını anlamadım. Bu arada oyun yandan göstermeli 2D.

    public float speed;
    public PlayerController player;
    public GameObject impactEffect;
    public int damageToGive;
    public Transform PlayerPosition;


    private Rigidbody2D rigidbody2D;


    // Use this for initialization
    void Start ()
    {
    this.rigidbody2D = GetComponent<Rigidbody2D> ();
    this.player = FindObjectOfType<PlayerController> ();
    PlayerPosition = GameObject.FindGameObjectWithTag ("Player").transform;

    if (this.player.transform.position.x < transform.position.x) {
    this.speed = -this.speed;

    }


    }

    void FixedUpdate()
    {
    float angle = Vector2.Angle(Vector2.right, this.rigidbody2D.velocity);
    if (this.rigidbody2D.velocity.y < 0)
    angle = -angle;
    transform.rotation = Quaternion.Euler(0, 0, angle);
    }

    // Update is called once per frame
    void Update ()
    {
    this.rigidbody2D.velocity = new Vector2 (this.speed, this.rigidbody2D.velocity.y);






    }

    void OnTriggerEnter2D (Collider2D other)
    {
    if (other.name == "Player") {
    HealthManager.HurtPlayer(this.damageToGive);
    }

    if (other.GetComponent<PlayerController>() == null && other.tag != "Ground")
    {
    return;
    }



    Instantiate (this.impactEffect, transform.position, transform.rotation);
    Destroy (gameObject);
    }
    }







  • player gameobjesini PlayerPosition'a sürükle, playerin konumunu alsın sürekli?
  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.