- Home /
EventTrigger do not work after my Intro script
Hello. I have an FPS project with simple Inventory system, that possible to put object to Inventory and use objects from Inventory when I turn camera on some UsableObject and click on item in the Inventory. Click on item realized through PointerClick in EventTrigger. Item itself is UI element, added from prefabs, stored in Array in GameManager and Attached (through the script when I put object at runtime) to Inventory_Panel, that have Grid order.
Everythings work allright, if I do not use my Intro script. But if is... Object in Inventory is no more clickable. Nothing to run. Method do not run at all.
Whats do Intro script: Just Deactivate FPS Controller and LookAt for time its run. Show and Hide some Intro_Panels and itself Texts. Run some animations for Texts, Lights, And Door GameObject. Show menu with Buttons. And give back FPS Controller and LookAt scripts, then I click the Play_Button.
public class Intro : MonoBehaviour {
public GameObject introPanel;
public Animator introPanelAnimator;
public GameObject introText1;
public GameObject introText2;
public FirstPersonController FPSController;
public GameObject mainMenuPanel;
public Animator mainMenuAnimator;
public Animator lightsAnimator;
public Door door;
public GameObject crosshair;
public LookAt lookAt;
void Start ()
{
FPSController.enabled = false;
lookAt.enabled = false;
crosshair.SetActive(false);
mainMenuPanel.SetActive(false);
ShowBlackScreen();
Invoke("ShowFirstScreen", 1f);
Invoke("ShowBlackScreen", 4f);
Invoke("ShowSecondScreen", 5f);
Invoke("ShowBlackScreen", 8f);
Invoke("HideIntroPanel", 9f);
// animate lights turns on
Invoke("LightsIntro", 9f);
// run door animation
Invoke("MoveDoor", 14f);
// run menu menu animation
Invoke("ShowMainMenu", 17f);
}
private void ShowBlackScreen()
{
introPanel.SetActive(true);
introText1.SetActive(false);
introText2.SetActive(false);
}
private void ShowFirstScreen()
{
introText1.SetActive(true);
introText2.SetActive(false);
}
private void ShowSecondScreen()
{
introText1.SetActive(false);
introText2.SetActive(true);
}
private void HideIntroPanel()
{
introPanelAnimator.SetTrigger("IntroPanelFadeOut");
}
private void LightsIntro()
{
lightsAnimator.SetTrigger("LightsIntro");
}
private void MoveDoor()
{
door.MoveDoor();
}
private void ShowMainMenu()
{
mainMenuPanel.SetActive(true);
mainMenuAnimator.SetTrigger("TextFadeIn");
}
public void StartGame()
{
mainMenuPanel.SetActive(false);
crosshair.SetActive(true);
FPSController.enabled = true;
lookAt.enabled = true;
}
public void QuitGame()
{
Application.Quit();
}
}
LookAt is script that cast a ray and change Cursor type depends on UsableObject or usual towards to camera. And looking for ButtonPressed for Use something.
So why this Intro script corrupted my TriggerEvent logic? Do you have some thoughts, guys?
P.S. ItemSlot logic. MoveDoor method - it is what stopping work.
public class PickableObject : MonoBehaviour {
public int poItemId;
private GameObject gameManager;
private void Start()
{
gameManager = GameObject.Find("GameManager");
}
private int GetUOItemId()
{
int uoItemId = 0;
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 1.5f))
{
if (hit.transform.tag == "Usable") // replace to if has component
{
uoItemId = hit.transform.GetComponent<UsableObject>().uoItemId;
}
}
return uoItemId;
}
public void MoveDoor()
{
if (GetUOItemId() == 1)
{
gameManager.GetComponent<Door>().MoveDoor();
}
else
{
print("This object cannot be used here.");
}
}
}