IT rekvalifikace s garancí práce. Seniorní programátoři vydělávají až 160 000 Kč/měsíc a rekvalifikace je prvním krokem. Zjisti, jak na to!
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
peter54321
Člen
Avatar
peter54321:21.9.2014 14:04

Zdravím,
Robím hru v Unity 3D a mám jeden vážny problém.
A to že mi nie vždy zareaguje Player na to že vrazí do Box collidera určeného pre smrť takže pokračuje v hra dalej aj keby nemal.
Prikladám scripty pre pohyb hráča:

using UnityEngine;
using System.Collections;

public class PC1 : MonoBehaviour
{
public KeyCode L;
public KeyCode R;

public float x = 0f;
public float y = 0f;
public float speedOfJump = 0f;

public AudioClip Jump;
private Vector2 newPos;

Animator animator;

void Start()
{
Vector2 posStart = new Vector2 (-0.3f, 0);
newPos = posStart;
animator = GetComponent<A­nimator> ();
}
void Update ()
{
bool dead = DeathPoint.dead;
bool timeOut = MeracCasu.timeOut;
if (dead || timeOut)
{
newPos = transform.position;
rigidbody2D.is­Kinematic = false;
}
if(!dead || !timeOut)
{
if (Input.GetKeyDown (L))
TurnLeft ();
if (Input.GetKeyDown (R))
TurnRight ();
}
if(rigidbody2D­.velocity.y < 0)
animator.SetTrig­ger("Fall");

transform.position = Vector2.MoveTowards (transform.po­sition, newPos, speedOfJump);
}
private void TurnLeft()
{
bool dead = DeathPoint.dead;
bool timeOut = MeracCasu.timeOut;
if (!dead || !timeOut)
{
Vector2 posL = new Vector2 (-x, y);
newPos = posL;
y += 0.5f;
float volume = ReactionScrip­t.volumeSound;
AudioSource.Pla­yClipAtPoint (Jump, transform.posi­tion,volume);
animator.SetTrigger ("Jump");
Vector2 scale = transform.local­Scale;
scale.x = 1;
transform.local­Scale = scale;
}
}
private void TurnRight()
{
bool dead = DeathPoint.dead;
bool timeOut = MeracCasu.timeOut;
if (!dead || !timeOut)
{
Vector2 posR = new Vector2 (x, y);
newPos = posR;
y += 0.5f;
float volume = ReactionScrip­t.volumeSound;
AudioSource.Pla­yClipAtPoint (Jump, transform.posi­tion,volume);
animator.SetTrigger ("Jump");
Vector2 scale = transform.local­Scale;
scale.x = - 1;
transform.local­Scale = scale;
}
}
void OnCollisionEn­ter2D(Collisi­on2D coll)
{
if (coll.gameObjec­t.tag == "Ground")
{
animator.SetTrig­ger("Dead");
}

}
}

a pre Box Collider:

using UnityEngine;
using System.Collections;

public class PC1 : MonoBehaviour
{
public KeyCode L;
public KeyCode R;

public float x = 0f;
public float y = 0f;
public float speedOfJump = 0f;

public AudioClip Jump;
private Vector2 newPos;

Animator animator;

void Start()
{
Vector2 posStart = new Vector2 (-0.3f, 0);
newPos = posStart;
animator = GetComponent<A­nimator> ();
}
void Update ()
{
bool dead = DeathPoint.dead;
bool timeOut = MeracCasu.timeOut;
if (dead || timeOut)
{
newPos = transform.position;
rigidbody2D.is­Kinematic = false;
}
if(!dead || !timeOut)
{
if (Input.GetKeyDown (L))
TurnLeft ();
if (Input.GetKeyDown (R))
TurnRight ();
}
if(rigidbody2D­.velocity.y < 0)
animator.SetTrig­ger("Fall");

transform.position = Vector2.MoveTowards (transform.po­sition, newPos, speedOfJump);
}
private void TurnLeft()
{
bool dead = DeathPoint.dead;
bool timeOut = MeracCasu.timeOut;
if (!dead || !timeOut)
{
Vector2 posL = new Vector2 (-x, y);
newPos = posL;
y += 0.5f;
float volume = ReactionScrip­t.volumeSound;
AudioSource.Pla­yClipAtPoint (Jump, transform.posi­tion,volume);
animator.SetTrigger ("Jump");
Vector2 scale = transform.local­Scale;
scale.x = 1;
transform.local­Scale = scale;
}
}
private void TurnRight()
{
bool dead = DeathPoint.dead;
bool timeOut = MeracCasu.timeOut;
if (!dead || !timeOut)
{
Vector2 posR = new Vector2 (x, y);
newPos = posR;
y += 0.5f;
float volume = ReactionScrip­t.volumeSound;
AudioSource.Pla­yClipAtPoint (Jump, transform.posi­tion,volume);
animator.SetTrigger ("Jump");
Vector2 scale = transform.local­Scale;
scale.x = - 1;
transform.local­Scale = scale;
}
}
void OnCollisionEn­ter2D(Collisi­on2D coll)
{
if (coll.gameObjec­t.tag == "Ground")
{
animator.SetTrig­ger("Dead");
}

}
}

 
Odpovědět
21.9.2014 14:04
Avatar
TrollKill
Člen
Avatar
TrollKill:21.9.2014 14:15

daj to do code...

 
Nahoru Odpovědět
21.9.2014 14:15
Avatar
peter54321
Člen
Avatar
peter54321:21.9.2014 14:46

ako ?

 
Nahoru Odpovědět
21.9.2014 14:46
Avatar
qwertyW
Tvůrce
Avatar
Odpovídá na peter54321
qwertyW:21.9.2014 16:40

4. čudlík zleva - vložit zdrojový kod

Editováno 21.9.2014 16:41
Nahoru Odpovědět
21.9.2014 16:40
Programuji, tedy jsem.
Avatar
Člen
Člen
Avatar
Odpovídá na peter54321
Člen:21.9.2014 16:41

Napis code na zaciatok kodu a /code na koniec kodu. Obidve daj do [] ;)

Editováno 21.9.2014 16:41
Nahoru Odpovědět
21.9.2014 16:41
...
Avatar
peter54321
Člen
Avatar
peter54321:21.9.2014 18:14

Script pre pohyb:

using UnityEngine;
using System.Collections;

public class PC1 : MonoBehaviour
{
        public KeyCode L;
        public KeyCode R;

        public float x = 0f;
        public float y = 0f;
        public float speedOfJump = 0f;

        public AudioClip Jump;
        private Vector2 newPos;

        Animator animator;

        void Start()
        {
                Vector2 posStart = new Vector2 (-0.3f, 0);
                newPos = posStart;
                animator = GetComponent<Animator> ();
        }
        void Update ()
        {
        bool dead = DeathPoint.dead;
        bool timeOut = MeracCasu.timeOut;
        if (dead || timeOut)
        {
                newPos = transform.position;
                rigidbody2D.isKinematic = false;
                print("dead or timeout");
        }
        if (Input.GetKeyDown (L))
        {
                TurnLeft ();
        }
        if (Input.GetKeyDown (R))
        {
                TurnRight ();
        }
        if (rigidbody2D.velocity.y < 0)
        {
                animator.SetTrigger ("Fall");
        }
        transform.position = Vector2.MoveTowards (transform.position, newPos, speedOfJump);
        }
        private void TurnLeft()
        {
                bool dead = DeathPoint.dead;
                bool timeOut = MeracCasu.timeOut;
                if (!dead || !timeOut)
                {
                        Vector2 posL = new Vector2 (-x, y);
                        newPos = posL;
                        y += 0.5f;
                        float volume = ReactionScript.volumeSound;
                        AudioSource.PlayClipAtPoint (Jump, transform.position,volume);
                        animator.SetTrigger ("Jump");
                        Vector2 scale = transform.localScale;
                        scale.x = 1;
                        transform.localScale = scale;
                }
        }
        private void TurnRight()
        {
                bool dead = DeathPoint.dead;
                bool timeOut = MeracCasu.timeOut;
                if (!dead || !timeOut)
                {
                        Vector2 posR = new Vector2 (x, y);
                        newPos = posR;
                        y += 0.5f;
                        float volume = ReactionScript.volumeSound;
                        AudioSource.PlayClipAtPoint (Jump, transform.position,volume);
                        animator.SetTrigger ("Jump");
                        Vector2 scale = transform.localScale;
                        scale.x = - 1;
                        transform.localScale = scale;
                }
        }
        void OnCollisionEnter2D(Collision2D coll)
        {
                if (coll.gameObject.tag == "Ground")
                {
                        animator.SetTrigger("Dead");
                }

        }
}

Script pre BoxCollider2D:

using UnityEngine;
using System.Collections;

public class DeathPoint : MonoBehaviour
{
        static public bool dead = false;

        void Start()
        {
                dead = false;
        }
        void Update()
        {
                bool timeOut = MeracCasu.timeOut;
                if (timeOut)
                {
                        dead = true;
                }
        }
        void OnTriggerEnter2D(Collider2D collider)
        {
                if (collider.CompareTag("Player"))
                {
                        Achievements.Deads();
                        dead = true;
                }
        }
}
 
Nahoru Odpovědět
21.9.2014 18:14
Avatar
Odpovídá na peter54321
Vojtěch Pospíchal:21.9.2014 18:41

Máš collider na objektu kde má hráč zemřít nastavený na trigger?

 
Nahoru Odpovědět
21.9.2014 18:41
Avatar
peter54321
Člen
Avatar
peter54321:21.9.2014 19:00

Samozrejme že mám
Nefunguje mi to iba občas,problém zrejme bude v scripte playera pretože ked som dal vypis v tomto scrip na podmienku dead or timeout, a presiel som z playerom cez boxcollider nastaveny ako trigger nič mi nevipisalo. Ale ako som napisal to sa stane iba občas. Raz to ide raz nie neviem kde môže by chyba.

 
Nahoru Odpovědět
21.9.2014 19:00
Avatar
peter54321
Člen
Avatar
peter54321:22.9.2014 15:34

Dobre tak sa zdá že som už tento problém vyriešil.
Mám dalšiu otázsku. Ako spravím loading screen ako má napríklad TimberMan?
Myslím take stmavnutie obrazovky do čierna a zasa naspäť keď je hra načítana.

 
Nahoru Odpovědět
22.9.2014 15:34
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 9 zpráv z 9.