07-06-2019, Saat: 15:04
(Son Düzenleme: 12-06-2019, Saat: 17:20, Düzenleyen: gbcm18.
Sebep: Çözüldü
)
[ÇÖZÜLDÜ!]
Merhaba arkadaşlar. Hem aranızda hemde Unity'de yeniyim. Sorun şu şekilde: Karakterim ninja para alınca para kaybolmuyor.Kodlar:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Player : MonoBehaviour {
private Rigidbody2D myRigidbody;
private Animator myAnimator;
private int skor;
public Text toplamSkor;
[SerializeField]
private GameObject anahtarVar;
[SerializeField]
public float hiz;
private bool sagaBak;
void Start () {
sagaBak = true;
skor = 0;
myRigidbody = GetComponent<Rigidbody2D> ();
myAnimator = GetComponent<Animator> ();
}
void Update () {
float yatay = Input.GetAxis ("Horizontal");
TemelHareketler(yatay);
YonCevir (yatay);
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
{
myAnimator.SetBool ("Run", true);
}
else
{
myAnimator.SetBool ("Run", false);
}
if (Input.GetKey (KeyCode.Space)) {
myAnimator.SetBool ("Attack", true);
}
else {
myAnimator.SetBool ("Attack", false);
}
}
private void TemelHareketler(float yatay){
myRigidbody.velocity = new Vector2 (yatay*hiz, myRigidbody.velocity.y);
}
private void YonCevir(float yatay)
{
if (yatay > 0 && !sagaBak || yatay < 0 && sagaBak)
{
sagaBak = !sagaBak;
Vector3 yon = transform.localScale;
yon.x *= -1;
transform.localScale = yon;
}
}
void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.tag == "altin") {
other.gameObject.SetActive (false);
skor = skor + 100;
SkorAyarla (skor);
}
if (other.gameObject.tag == "key") {
other.gameObject.SetActive (false);
anahtarVar.SetActive (true);
}
}
void SkorAyarla(int count)
{
toplamSkor.text= "Skor:" + count.ToString();
}
}
Merhaba arkadaşlar. Hem aranızda hemde Unity'de yeniyim. Sorun şu şekilde: Karakterim ninja para alınca para kaybolmuyor.Kodlar:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Player : MonoBehaviour {
private Rigidbody2D myRigidbody;
private Animator myAnimator;
private int skor;
public Text toplamSkor;
[SerializeField]
private GameObject anahtarVar;
[SerializeField]
public float hiz;
private bool sagaBak;
void Start () {
sagaBak = true;
skor = 0;
myRigidbody = GetComponent<Rigidbody2D> ();
myAnimator = GetComponent<Animator> ();
}
void Update () {
float yatay = Input.GetAxis ("Horizontal");
TemelHareketler(yatay);
YonCevir (yatay);
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
{
myAnimator.SetBool ("Run", true);
}
else
{
myAnimator.SetBool ("Run", false);
}
if (Input.GetKey (KeyCode.Space)) {
myAnimator.SetBool ("Attack", true);
}
else {
myAnimator.SetBool ("Attack", false);
}
}
private void TemelHareketler(float yatay){
myRigidbody.velocity = new Vector2 (yatay*hiz, myRigidbody.velocity.y);
}
private void YonCevir(float yatay)
{
if (yatay > 0 && !sagaBak || yatay < 0 && sagaBak)
{
sagaBak = !sagaBak;
Vector3 yon = transform.localScale;
yon.x *= -1;
transform.localScale = yon;
}
}
void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.tag == "altin") {
other.gameObject.SetActive (false);
skor = skor + 100;
SkorAyarla (skor);
}
if (other.gameObject.tag == "key") {
other.gameObject.SetActive (false);
anahtarVar.SetActive (true);
}
}
void SkorAyarla(int count)
{
toplamSkor.text= "Skor:" + count.ToString();
}
}