Arama butonu
Bu konudaki kullanıcılar: 1 misafir, 1 mobil kullanıcı
1
Cevap
360
Tıklama
0
Öne Çıkarma
Unity ödevi script yardım
E
5 yıl
Er
Konu Sahibi

Merhaba final projesi için oyun yaptım fakat oyun sorunsuz calısmakta ama score kısmı hatalı


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SpawnManager : MonoBehaviour {
public GameObject[] animalPrefabs = new GameObject[3];
private float spawnRangeX = 17f;
private float spawnZ = 20f;
private float startDelay = 2f;
private float spawnInterval = 1.2f;
public static int score = 0;
public Text scoreText;

public static bool isAlive = true;
public GameObject RestartButton;

void Start () {
InvokeRepeating ("SpawnRandomAnimals", startDelay, spawnInterval);
}

// Update is called once per frame
void Update () {
if (!isAlive) {

RestartButton.SetActive (true);
isAlive = true;
}

scoreText.text = "Score:" + score;

}
public static void Score (string animal) {

switch (animal) {
case "Animal1(Clone)":
score += 5;
break;
case "Animal2(Clone)":
score += 100;
break;
case "Animal3(Clone)":
score += 25;
break;
}

}
/// <summary>
/// OnCollisionEnter is called when this collider/rigidbody has begun
/// touching another rigidbody/collider.
/// </summary>
/// <param name="other">The Collision data associated with this collision.</param>
void OnCollisionEnter (Collision other) {
if (other.gameObject.name == "Animal1(Clone)")
score += 5;
}
public static void Die () {
isAlive = false;
}
public void Restart () {
RestartButton.SetActive (false);
score = 0;
SceneManager.LoadScene (0);
}

void SpawnRandomAnimals () {
int animalIndex = Random.Range (0, animalPrefabs.Length);
Vector3 spawnPos = new Vector3 (Random.Range (-spawnRangeX, spawnRangeX), 0, spawnZ);
Instantiate (animalPrefabs[animalIndex], spawnPos, animalPrefabs[animalIndex].transform.rotation);
}
}

DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.

Üye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.

Üye Ol Şimdi Değil





< Bu mesaj bu kişi tarafından değiştirildi El-HusseinBinHattab -- 21 Haziran 2020; 19:18:48 >