Question by
RancidWheel · Apr 08, 2017 at 08:27 PM ·
camera2d gamecharactercontrollerdestroy objectsandbox
main camera is being destoyed by the script. i want to destroy blocks with left mouse click, not the camera
i'm using the Standard Assets 2D character. i changed in the "PlatformerCharacter2D" code this part
private void Update()
{
if (!m_Jump)
{
// Read the jump input in Update so button presses aren't missed.
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
if (Input.GetMouseButtonDown(0))
{
Vector3 c = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D colpo = Physics2D.Raycast(transform.position, c - transform.position);
if (colpo.collider.gameObject != null)
{
Destroy(colpo.collider.gameObject);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Rect or Camera transform? 0 Answers
Character controller for fixed perspective camera (moving relative to arbitrary point on screen) 0 Answers
2D box collider always detecting player,2D Box colliders detecting player when he is not there 1 Answer