Hi! i am new with this program and i was doing the ball tutorial and i would like to know how can i make an image appear when i pick up all the balls? Not just a text. Using script
thx
this is the script i’m using:
using System.Collections;
using System.Collections.Generic; using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float MoveHorizontal = Input.GetAxis ("Horizontal");
float MoveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (MoveHorizontal, 0.0f, MoveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Pick Up Objects: " + count.ToString ();
if (count >= 7)
{
winText.text = "You Win!";
}
}
}
If you’re talking about displaying a flat UI type image, you can have a raw image component set with the texture you want displayed, and have it attached to an inactive gameobject. Whenever you want to display the image you just enable the gameobject. When you want the image to go away you just disable it.
like the tutorial, when you finish collect all pick up objects, a text appears “you win”
i want the same thing to happens, but with an image to show up when i finish collecting all objects.
so my question is: how can i do it with script?
Please, think for a moment. Your image is always up because you didn’t deactived it… Deactive manually or even better put in Awake/Start method [quote]
showImage.enabled = false;
[/quote]
Also, you have to assign this image to showImage in inspector.
Could you help me again, @Prastiwar ? i’m doing the “roguelike 2d” tutorial, everything was fine till i got an error with a code “gameover”. To make sure i was doing nothing wrong, i “ctrl c + ctrl v” the tutorial script and samething happens. Take a look:
Errors usually say everything you need to know what’s going wrong. So, it’s telling you that you don’t have “GameOver” method there is no something like void GameOver()) in GameManager script.
i used the tutorial script, how can i fix it? i dont understand this C language. i have to type in the gamemanager script that void code? if yes, ok, but i dont understand what exactly i have to write >.<