Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

unity 3D błąd w skrypcie


Rekomendowane odpowiedzi

Opublikowano

Siemka mam błąd w tym bloku

	IEnumerator waitFunction()
	{
		yield return new WaitForSeconds(1);
			if (currentFood > 0) {
			currentFood -= 1;
		} else {
			takeHit(10);
		}
			if (currentWater > 0) {
			currentWater -= 1;
		} else {
			takeHit(10);
		}
	}

Unexpected symbol `(', expecting `)', `,', `;', `[', or `='

 

Dawałem już praktycznie każdy system spację usuwałem je dodawałem inne i nic nie wiem co już zrobić a bez tego gra nie włączy się

TEMAT


 


Opublikowano

Daj cały plik, bo ten fragment jest bez błędów. Najpewniej wcześniej gdzieś nie domknąłeś jakichś nawiasów i to dlatego.

Opublikowano

;-; aż wstyd przyznać zabrakło mi klamry } do zamknięcia poprzedniego bloku ;-;

 

Dzięki że wspomniałeś o poprzednich nawiasach bo tak bym nie zauważył bo sporo tego tam tam

 

@Fireho a jednak kolejny błąd podczas testowania gry spada mi woda + jedzenie do 0 w tempie szybszym niż ustawiłem + podczas gdy jakaś zmienna osiąga 0 gra włącza PAUSE którego nie umiem wyłączyć

using UnityEngine;
using System.Collections;

public class PlayerStats : MonoBehaviour {

	private float maxHealth = 100;
	private float currentHealth = 50;
	private float maxArmour = 100;
	private float currentArmour = 0;
	private float maxStamina = 300;
	private float currentStamina = 300;
	private float maxWater = 100;
	private float currentWater = 100;
	private float maxFood = 100;
	private float currentFood = 100;

	private float barWidth = 100;
	private float barHeight = 100;

	private float canHeal = 0.0f;
	private float canRegenerate = 0.0f;

	private CharacterController chCont;
	private CharacterMotor chMotor;
	private Vector3 lastPosition;

	public Texture2D healthTexture;
	public Texture2D staminaTexture;
	public Texture2D foodTexture;
	public Texture2D waterTexture;

	public float walkSpeed = 10.0f;
	public float runSpeed = 20.0f;

	public GUITexture hitTexture;


	void Awake()
	{
		barHeight = Screen.height * 0.02f;
		barWidth = barHeight * 10.0f;

		chCont = GetComponent<CharacterController>();
		chMotor = GetComponent<CharacterMotor>();

		lastPosition = transform.position;
	}
	
	void OnGUI()
	{
		GUI.DrawTexture(new Rect(Screen.width - barWidth - 700,
		                         Screen.height - barHeight * 2 - 20,
		                         currentHealth * barWidth / maxHealth,
		                         barHeight),
		                healthTexture);
		GUI.DrawTexture(new Rect(Screen.width - barWidth - 700,
		                         Screen.height - barHeight * 3 - 30,
		                         currentStamina * barWidth / maxStamina,
		                         barHeight),
		                staminaTexture);
		GUI.DrawTexture(new Rect(Screen.width - barWidth - 700,
		                         Screen.height - barHeight * 4 - 40,
		                         currentWater * barWidth / maxWater,
		                         barHeight),
		                waterTexture);
		GUI.DrawTexture(new Rect(Screen.width - barWidth - 700,
		                         Screen.height - barHeight * 5 - 50,
		                         currentFood * barWidth / maxFood,
		                         barHeight),
		                foodTexture);
	}

	void Start()
	{

		Rect currentRes = new Rect(-Screen.width * 0.5f,
		                           -Screen.height * 0.5f,
		                           Screen.width,
		                           Screen.height);
		hitTexture.pixelInset = currentRes;
	}

	void Update()
	{
		{
			StartCoroutine (waitFunction ()); 
		}
		if (canHeal > 0.0f) {
			canHeal -= Time.deltaTime;
		}
		if (canRegenerate > 0.0f) {
			canRegenerate -= Time.deltaTime;
		}

		if (canHeal <= 0.0f && currentHealth < maxHealth) {
			regenerate (ref currentHealth, maxHealth);
		}
		if (canRegenerate <= 0.0f && currentStamina < maxStamina) {
			regenerate (ref currentStamina, maxStamina);
		}
	}
	IEnumerator waitFunction()
	{
		if (currentFood > 10) {
			currentFood -= 1;
			yield return new WaitForSeconds (10.0f);
		} else {
			takeHit(10);
			yield return new WaitForSeconds (10.0f);
		}
		if (currentWater > 10) {
			currentWater -= 1;
			yield return new WaitForSeconds (10.0f);
		} else {
			takeHit(10);
			yield return new WaitForSeconds (10.0f);
		}
	}

	void FixedUpdate () 
	{
		float speed = walkSpeed;
		
		if(chCont.isGrounded && Input.GetKey(KeyCode.LeftShift) && lastPosition != transform.position && currentStamina > 0) {
			lastPosition = transform.position;
			speed = runSpeed;
			currentStamina -= 1;
			currentStamina = Mathf.Clamp(currentStamina, 0, maxStamina);
			canRegenerate = 5.0f;
		}	
		
		chMotor.movement.maxForwardSpeed = speed;
	}

	void takeHit(float demage) 
	{

		Destroy(Instantiate(hitTexture), 0.15f);

		if(currentArmour > 0) {
			currentArmour = currentArmour - demage;
			if(currentArmour < 0) {
				currentHealth += currentArmour;
				currentArmour = 0;
			}
		} else {
			currentHealth -= demage;
		}

		if(currentHealth < maxHealth) {
			canHeal = 5.0f;
		}

		currentArmour = Mathf.Clamp(currentArmour, 0, maxArmour);
		currentHealth = Mathf.Clamp(currentHealth, 0, maxHealth);
	}

	void regenerate(ref float currentStat, float maxStat)
	{
		currentStat += maxStat * 0.005f;
		Mathf.Clamp(currentStat, 0, maxStat);
	}

}

Oto cały skrypt pisany w C#

TEMAT


 


Opublikowano
IEnumerator waitFunction()
{
if (currentFood > 10)
currentFood -= 1;
else
takeHit(10);
 
if (currentWater > 10)
currentWater -= 1;
else
takeHit(10);
 
yield return new WaitForSeconds (10.0f);
StartCoroutine(waitFunction());
}

i StartCoroutine (waitFunction ()); wywal z update i wklej do start

3053080006.png

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...