Hey, I am very beguiner in scripting and I have struggle with a simple interation.
My goal is to replace an asset (bloc1) by an other one (bloc2) on player input.
The only difference between both blocs is that one has some text extruded.
Even better since I can activate or disactivate a block depending if the player step into a box collider.
Just need to attached this script to your box collider and drag and drop your blocks into the public variable slot.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InstStart2 : MonoBehaviour
{
public GameObject baseBlock;
public GameObject blockText;
// Use this for initialization
void Start () {
baseBlock.SetActive(true);
blockText.SetActive(false);
}
// Update is called once per frame
private void OnTriggerEnter(Collider player)
{
if (player.gameObject.tag == "Player")
{
baseBlock.SetActive(false);
blockText.SetActive(true);
Debug.Log("entering");
}
}
private void OnTriggerExit(Collider player)
{
if (player.gameObject.tag == "Player")
{
baseBlock.SetActive(true);
blockText.SetActive(false);
Debug.Log("exiting");
}
}
}