How to replace an asset by an other one on player input
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.
The idea is to create an area near the wall in wich when the player press an input, the wall show the extruded text.
There might be other way to do it than replace it but at my level of knowledge, this seems the easiest way to do it.
It doesn't have to comeback in his initial state. The interaction is one sided.
Thanks in advance to anyone who could help me.
can you specify what you mean by player input? for example if key F is pressed, or on mouse click?
Answer by Vynzt · Nov 25, 2018 at 12:48 PM
I manage to find a simple way to do it.
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");
}
}
}