Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

cannot convert type HealthandInventory to int

$
0
0
Hey guys, this is a project I am working on and I am getting this error in Unity - Cannot implicitly convert type HealthandInventory to type int - HealthandInventory is the name of one of the scripts I have created, this error I am getting is in my PitTrigger Script. Any Ideas? Error says it is on line 25 in the 3rd nested IF Statement. Here's the code. using UnityEngine; using System.Collections; public class PitTrigger : MonoBehaviour { public int _playerlives; void Start () { _playerlives = 3; } void OnTriggerEnter2D (Collider2D other) { if (other.tag == "Player") { GameObject trigger = GetNearestCP (); if (trigger != null) { if (other.GetComponent()._playerLives > 0) { other.transform.position = trigger.transform.position; other.GetComponent()._playerLives = other.GetComponent(); } else { Application.LoadLevel (0); } } else { Debug.Log ("No Checkpoint Found"); } } else { Destroy (other.gameObject); } } GameObject GetNearestCP () { GameObject[] checkpoints = GameObject.FindGameObjectsWithTag ("Checkpoint"); GameObject nearestCheckpoint = null; float shortestDistance = Mathf.Infinity; foreach (GameObject checkpoint in checkpoints) { Vector3 checkpointPosition = checkpoint.transform.position; float distance = (checkpointPosition - transform.position).sqrMagnitude; CheckpointTrigger triggerRef = checkpoint.GetComponent(); if (distance < shortestDistance && triggerRef.isCpTriggered == true) { nearestCheckpoint = checkpoint; shortestDistance = distance; } } return nearestCheckpoint; } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>