اذهب إلى المحتوى

السؤال

نشر

السلام عليكم 

وانا اتتبع احد الدروس الانجليزية على الانترنت منذ اسبوع لم اجد حتى مشكلة الا ان ظهرت مشكلة اليوم ورغم المحاولات لحلها لم استطع و ارجو ان اجد الحل عندكم

 

رسالة الخطأ في يونتي 

 

Assets/Scripts/LevelManager.cs(41,20): error CS0029: Cannot implicitly convert type `ResetOnRespawn' to `ResetOnRespawn[]'

 

 

يتم تسطير على الخطأ FindObjectOfType <ResetOnRespawn> ();

 

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

public class LevelManager : MonoBehaviour {

	public float waitToRespawn;
	public PlayerController thePlayer;

	public GameObject deathSplosion;

	public int coinCount;

	public Text CoinText;

	public Image heart1;
	public Image heart2;
	public Image heart3;

	public Sprite heartFull;
	public Sprite heartHalf;
	public Sprite heartEmpty;

	public int maxHealth;
	public int healthCount;

	private bool respawning;

	public ResetOnRespawn[] objectsToReset;

	// Use this for initialization
	void Start () {

		thePlayer = FindObjectOfType<PlayerController>();

		CoinText.text = "Coins: " + coinCount;

		healthCount = maxHealth;

		objectsToReset = FindObjectOfType <ResetOnRespawn> ();
	}
	
	// Update is called once per frame
	void Update () {
		if(healthCount <= 0 && !respawning)
		{
			Respawn();
			respawning = true;
		}
	}

	public void Respawn()
	{
		StartCoroutine("RespawnCo");
	}

	public IEnumerator RespawnCo()
	{
		thePlayer.gameObject.SetActive(false);

		Instantiate(deathSplosion, thePlayer.transform.position, thePlayer.transform.rotation);

		yield return new WaitForSeconds(waitToRespawn);

		healthCount = maxHealth;
		respawning = false;
		UpdateHeartMeter();

		thePlayer.transform.position = thePlayer.respawnPosition;
		thePlayer.gameObject.SetActive(true);
	}

	public void AddCoins(int CoinsToAdd)
	{
		coinCount += CoinsToAdd;

		CoinText.text = "Coins: " + coinCount;
	}

	public void HurtPlayer(int damageToTake)
	{
		healthCount -= damageToTake;
		UpdateHeartMeter();
	}

	public void UpdateHeartMeter()
	{
		switch(healthCount)
		{
			case 6:
				heart1.sprite = heartFull;
				heart2.sprite = heartFull;
				heart3.sprite = heartFull;
				return;

			case 5:
				heart1.sprite = heartFull;
				heart2.sprite = heartFull;
				heart3.sprite = heartHalf;
				return;

			case 4:
				heart1.sprite = heartFull;
				heart2.sprite = heartFull;
				heart3.sprite = heartEmpty;
				return;

			case 3:
				heart1.sprite = heartFull;
				heart2.sprite = heartHalf;
				heart3.sprite = heartEmpty;
				return;

			case 2:
				heart1.sprite = heartFull;
				heart2.sprite = heartEmpty;
				heart3.sprite = heartEmpty;
				return;

			case 1:
				heart1.sprite = heartHalf;
				heart2.sprite = heartEmpty;
				heart3.sprite = heartEmpty;
				return;

			case 0:
				heart1.sprite = heartEmpty;
				heart2.sprite = heartEmpty;
				heart3.sprite = heartEmpty;
				return;

			default:
				heart1.sprite = heartEmpty;
				heart2.sprite = heartEmpty;
				heart3.sprite = heartEmpty;
				return;

		}
	}
}

 

 

 

Recommended Posts

  • 0
نشر

شكرا لك اخي على المساعدة لكن المشكل مازال قائم

Assets/Scripts/LevelManager.cs(42,18): error CS1061: Type `ResetOnRespawn[]' does not contain a definition for `add' and no extension method `add' of type `ResetOnRespawn[]' could be found. Are you missing an assembly reference?

 

 

ويتم التسطير على add في فزيال ستوديو

  • 0
نشر
  • استبدله الكود كله وي هذا رح يشتغل

  •  

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

    public class LevelManager : MonoBehaviour {

        public float waitToRespawn;
        public PlayerController thePlayer;

        public GameObject deathSplosion;

        public int coinCount;

        public Text CoinText;

        public Image heart1;
        public Image heart2;
        public Image heart3;

        public Sprite heartFull;
        public Sprite heartHalf;
        public Sprite heartEmpty;

        public int maxHealth;
        public int healthCount;

        private bool respawning;

        public ResetOnRespawn[] objectsToReset;

        // Use this for initialization
        void Start () {

            thePlayer = FindObjectOfType<PlayerController>();

            CoinText.text = "Coins: " + coinCount;

            healthCount = maxHealth;

            objectsToReset.Add( FindObjectOfType <ResetOnRespawn> ());
        }

        // Update is called once per frame
        void Update () {
            if(healthCount <= 0 && !respawning)
            {
                Respawn();
                respawning = true;
            }
        }

        public void Respawn()
        {
            StartCoroutine("RespawnCo");
        }

        public IEnumerator RespawnCo()
        {
            thePlayer.gameObject.SetActive(false);

            Instantiate(deathSplosion, thePlayer.transform.position, thePlayer.transform.rotation);

            yield return new WaitForSeconds(waitToRespawn);

            healthCount = maxHealth;
            respawning = false;
            UpdateHeartMeter();

            thePlayer.transform.position = thePlayer.respawnPosition;
            thePlayer.gameObject.SetActive(true);
        }

        public void AddCoins(int CoinsToAdd)
        {
            coinCount += CoinsToAdd;

            CoinText.text = "Coins: " + coinCount;
        }

        public void HurtPlayer(int damageToTake)
        {
            healthCount -= damageToTake;
            UpdateHeartMeter();
        }

        public void UpdateHeartMeter()
        {
            switch(healthCount)
            {
            case 6:
                heart1.sprite = heartFull;
                heart2.sprite = heartFull;
                heart3.sprite = heartFull;
                return;

            case 5:
                heart1.sprite = heartFull;
                heart2.sprite = heartFull;
                heart3.sprite = heartHalf;
                return;

            case 4:
                heart1.sprite = heartFull;
                heart2.sprite = heartFull;
                heart3.sprite = heartEmpty;
                return;

            case 3:
                heart1.sprite = heartFull;
                heart2.sprite = heartHalf;
                heart3.sprite = heartEmpty;
                return;

            case 2:
                heart1.sprite = heartFull;
                heart2.sprite = heartEmpty;
                heart3.sprite = heartEmpty;
                return;

            case 1:
                heart1.sprite = heartHalf;
                heart2.sprite = heartEmpty;
                heart3.sprite = heartEmpty;
                return;

            case 0:
                heart1.sprite = heartEmpty;
                heart2.sprite = heartEmpty;
                heart3.sprite = heartEmpty;
                return;

            default:
                heart1.sprite = heartEmpty;
                heart2.sprite = heartEmpty;
                heart3.sprite = heartEmpty;
                return;

            }
        }
    }
     

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...