Due to to pandemic going on, I decided to start using Unity (totally as a newbie, all I know is just some simple public, private, ifs, int, voids, modeling and components and some other minor stuff), which is hard at the start especially f you start it as a hobby. Anyways, back to the main point. I’m creating a game (by watching unity tutorials and get used to it and also take some help from others). I want to start it simple by creating a starter game (for android and later PC) in which a person taps/clicks and a block of on of my assets (shown in the picture) drops and later disappears and then adding a shop and all that stuff for later, but for now I need you guys to help me out and explain to me how to make that possible (for android and if possible for PC as well). I looked up a few videos but nothing seem to work.BTW, was inspired with this idea by the Android Easter egg. Also, can I know what’s the appropriate code?
I will update this, if there is an option to do this.
Just to make it clearer, I need the help for running the app for Android, but if it is possible, help for PC would be awesome as well.
If you’re having trouble reading:
I just need help with creating a game that when a player touches any location on their screen, a random asset (shown in image) should spawn and disappear after a few seconds 
Did you even google? I saw many Youtube tutorials appear when I searched for “unity touch to spawn”
Yes, I did. I looked up all that looked relevent including the one on Unity’s channel. But, want them to spawn randomly each wiith the same chances of being spawned, that’s the difficulty I’m having to deal with 
Make a public GameObject array variable in your script, populate it with the prefabs you want to select from.
You can use Random.Range()
and supply the .Length
property of that array to pick one randomly.
Once you select it, spawn that one!
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InstantiateByTouch : MonoBehaviour {
[SerializeField]
private GameObject[] prefabs;
private int randomPrefab;
private Touch touch;
private Vector2 TouchPos;
//Update s called once per frame
void Update() {
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
TouchPos = Camera.mainScreenToWorldPoint(touch.position);
if (touch.phase == TouchPhase.Began)
{
randomPrefab = Random.Range(0, 5);
Instantiate(prefabs[randomPrefab], TouchPos, Quaternion.identity);
}
}
}
}
So, I found a video on YouTube https://www.youtube.com/watch?v=KSbk776kTfY
I copied this exact code a writen it in Unity. No issues were found in Visual Studio, no but Unity had to give an error (lol). It gave me an error as shown in the picture 
Well, what do I do?
You have a script called “Touch”. On line 20, the compiler thinks that Touch refers to your own Touch script, but Input.GetTouch returns Unity’s Touch. Rename your script and class to something else.
2 Likes
Well, thank you for the solution. I didn’t need that “Touch” script so I deleted it and noticed that the Camera.main.ScreenToWorldPoint was Camera.mainScreenToWorldPoint. Now, all the errors are fixed. I accept all of your replies as answers. Thank you all for your time 