Hi,
I am not really good at programming and just started learning Unity3D and game programming and I would like to ask help on how to enable may gameobject(a shield) to be true using c#. Because what I did with my gameobject(a shield) using a c# script attached to it is I declared this at the Start() function:
here is the code on my shield gameobject:
using UnityEngine;
using System.Collections;
public class Shield : MonoBehaviour {
// Use this for initializationk
void Start () {
renderer.enabled = false;
}
// Update is called once per frame
void Update () {
}
public void Render() {
renderer.enabled = true;
}
}
From my understanding what the code does is it makes the gameobject(the shield) invisible at the start. Now what I want to learn is how to make the gameobject(the shield) appear again once another gameobject(a powerup) has collided with another different gameobject(player) also.
for more reference here is my code on the power up gameobject:
using UnityEngine;
using System.Collections;
public class Powerup : MonoBehaviour {
public Shield shield;
float xAxis;
float yAxis;
// Use this for initialization
void Start () {
xAxis = Random.Range(-2,2);
yAxis = Random.Range(-2,2);
if((xAxis == 0) || (yAxis == 0)) {
xAxis = Random.Range(-2,2);
yAxis = Random.Range(-2,2);
}
}
// Update is called once per frame
void Update () {
Vector3 position = new Vector3(0, -1) * Time.deltaTime;
transform.Translate(position);
if (((transform.position.y > 5.2f) || (transform.position.y < -4.7f)) ((transform.position.x > 18f) || ((transform.position.x < -11.5f)))) {
transform.position = new Vector3(0.0f,0.0f);
xAxis = Random.Range(-2,2);
yAxis = Random.Range(-2,2);
}
}
void OnTriggerEnter(Collider Player) {
if(Player.tag == “Player”) {
transform.position = new Vector3(0.0f,0.0f);
xAxis = Random.Range(-2,2);
yAxis = Random.Range(-2,2);
shield.Render();
}
}
}
I would really appreciate any help that can be provided comments and feedback are really appreciated on my end, Thanks in advance everyone!