Diskuze: Unity 3D problémy Petra54321
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.

Člen

Zobrazeno 9 zpráv z 9.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
4. čudlík zleva - vložit zdrojový kod
Napis code na zaciatok kodu a /code na koniec kodu. Obidve daj do []
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;
}
}
}
Máš collider na objektu kde má hráč zemřít nastavený na trigger?
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.
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.
Zobrazeno 9 zpráv z 9.