Scripting Portal
Hello everyone.So my concept is that i need to script my portal in wich i have added a box collider to check if a player is meeting some creterias.Due that the game is for mobile i'm using only buttons to move around with trigger event. So what i need is to if the player is meeting the creterias the box collider(portal to be opened) will change to isTrigger and let the player to pass.
this is my portal attached script: using UnityEngine;
public class Currency : MonoBehaviour { private GameObject currency; private CurrencyInvoke playerScript;
private void Start()
{
playerScript = GetComponent<CurrencyInvoke>();
}
void Update()
{
if (gameObject.tag == "Fox")
{
if (playerScript.counter != 2)
{
Debug.Log("You need more coins");
GetComponent<BoxCollider>().isTrigger = false;
}
else
{
GetComponent<BoxCollider>().isTrigger = true;
}
}
}
}
this is my player attached script using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CurrencyInvoke : MonoBehaviour { GameObject coins; public int counter = 0;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Coin")
{
counter++;
Debug.Log(counter);
}
}
}
Your answer
Follow this Question
Related Questions
C# OnTriggerEnter Issue 3 Answers
Enemy Trigger Colliders are triggering my player's trigger collider. Why? 1 Answer
Problem With Triggers? 0 Answers
OnTriggerEnter 1 Answer
OnTriggerEnter not firing 2 Answers