#Help with Instantiating a 3D object with touch

1 messages · Page 1 of 1 (latest)

celest granite
#

Hi All, I've been watching Brackeys videos on how to build a turret defense game on YouTube and I've been trying to replicate it but for Mobile. I'm stuck on Episode 6 where if the space does not have a turret, pressing a mouse click would put down a turret. I've been trying to figure out how I can replace part of the code for touch input but can't figure it out. Can anyone help? See code below:

void OnMouseButtonDown()
{

if(turret != null)

{

    Debug.Log("Can't build there! - TODO: Display on screen.");
    return;

}

GameObject turretToBuild = BuildManager.instance.GetturretToBuild();
turret = (GameObject) Instantiate (turretToBuild, transform.position, transform.rotation);

}

last heart
#

I think the event you're looking for also works on mobile (touch), it's just that you might have gotten the name wrong?

#

OnMouseButtonDown doesn't show up when I try it out.

#

So I assume you mean OnMouseDown.

#

In this video we create functionality for building turrets in the game.

♥ Support my videos on Patreon: http://patreon.com/brackeys/

● Download the turrets: http://devassets.com/assets/tower-defense-assets/
● Download Project on GitHub: http://bit.ly/29rvq0Y

····················································································
...

▶ Play video
#

Looking at his code, he does use OnMouseDown as well.

celest granite
#

Yeah you're right. I got the code to work. Thanks!