I have an issue where Unity freezes at the exact moment before I touch (or possibly as I touch) a trigger. It doesn't do it every time...sometimes the first run through, sometimes the tenth, but it always does it (I have it set to keep taking me back to the beginning so I can figure out what's causing it. Please help! I have included some of the code where I think the issue might be. I'd be happy to include the whole script if that's helpful.
void Start()
{
m_Character = GetComponent();
player = GetComponent();
playerCol = GetComponent();
animator.SetFloat("Speed", 0);
answerCounter = 0;
nameTheTriad.gameObject.SetActive(false);
correctCheck = 0;
}
private void Update()
{
if (!stopped)
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; //finds if we're trying to move and generates a velocity, kind of...sent to fixed update
}
if (Input.GetButtonDown("Jump") && !stopped)
{
jump = CrossPlatformInputManager.GetButtonDown("Jump");
//animator.SetBool("IsJumping", true);
}
if (player.transform.position.y < -10)
{
TriadManager.instance.RestartGame();
}
if (stopped) //all of this is checking the users choices of notes in the triad
{
clicked = CheckClick();
print(answerCounter);
if (answerCounter < 3 && clicked != null && clicked.GetComponent().sprite != clickedSprite)
{
clicked.GetComponent().sprite = clickedSprite;
if (clicked.name == answer[0] || clicked.name == answer[1] || clicked.name == answer[2])
{
correctCheck++;
}
answerCounter++;
}
if (answerCounter == 3 && !inAction)
{
inAction = true;
if (correctCheck == 3)
{
StartCoroutine(waitTwo(true));
}
else if (correctCheck < 3)
{
StartCoroutine(waitTwo(false));
}
}
}
}
// Update is called once per frame
void FixedUpdate()
{
if (!stopped)
{
m_Character.Move(horizontalMove, false, jump);
jump = false;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
}
}
GameObject CheckClick()
{
if (Input.GetMouseButtonDown(0)) //checks to see what the click is
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
if (hit.collider != null)
{
return hit.collider.gameObject;
}
}
return null;
}
private void OnTriggerEnter2D(Collider2D collision)
{
print("Triggered");
if (collision.tag == "trigger" && !triggered)
{
triggered = true;
stopped = true;
player.velocity = new Vector3(0, 0, 0);
thisTrigger = collision;
thisTrigger.gameObject.SetActive(false);
TriadGenerator(collision.name);
}
if(collision.tag == "enemy")
{
TriadManager.instance.RestartGame();
}
}
↧