Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Android 2D Game, help with food and tapping.

Discussion in 'Android' started by DatCaptainHorse, Mar 29, 2014.

  1. DatCaptainHorse

    DatCaptainHorse

    Joined:
    Mar 29, 2014
    Posts:
    13
    Hi, im new to Unity. Im doing android game, how do i make a Micro (A sphere) go get food and eat it? Then it grows and produces more Micros. And how to make tapping screen spawn some delicious food there? I have tried some codes but no luck.


    Edit: Im making some progress! Now how i can make those spheres (food) to spawn where is being touched?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TapFood : MonoBehaviour {
    6.     void Update() {
    7.  
    8.         GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    9.         sphere.transform.position = new Vector3(0, 1.5F, 0);
    10.         sphere.transform.localScale = new Vector3(0.1F, 0.1F, 0.1F);
    11.  
    12.     }
    13. }
    14.  
     
    Last edited: Mar 30, 2014
  2. bobochobo

    bobochobo

    Joined:
    Dec 4, 2012
    Posts:
    7
    Put those three lines of code in start, there's no need to set them each frame.

    To spawn food you'll need to have a look at using an if statement to check for touches, then instantiate your food gameobject at a certain point. To find the point you'll need to use raycasting to cast a ray from the touch point to the plane or whatever the food will spawn on, then use the .point variable of the hit object.
     
  3. DatCaptainHorse

    DatCaptainHorse

    Joined:
    Mar 29, 2014
    Posts:
    13
    But I dont know anything about instantiating, rays..
     
  4. sendmyfile

    sendmyfile

    Joined:
    Jan 31, 2014
    Posts:
    9
    hello there newbie, I am one as well, your goal is simple, I could write the code for you, but it would not do you any good.
    if you intend to publish an app in the end, you really should check out the resource provided by Unity first, it helped me A LOT.
    start at script basics: http://unity3d.com/learn/tutorials/modules/beginner/scripting,
    after you go through them you might have a basic understanding of unity scripting, then go to: http://unity3d.com/learn/tutorials/modules/beginner/navigation, you should know how to move your sphere to your food. afterward check out http://unity3d.com/learn/tutorials/modules/beginner/physics, this provides knowledge of " eating your food". for tapping part, watch : http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/mobile-development as well as http://unity3d.com/learn/tutorials/modules/beginner/platform-specific/multitouch-input.
    after you know some of the basics you are well on your way to something great.
     
  5. DatCaptainHorse

    DatCaptainHorse

    Joined:
    Mar 29, 2014
    Posts:
    13
    Thanks.


    Is there way that when i touch play button it loads scene1? Theres GuiText and GuiTexture (it looked cool like that and might give some extra functions) and when i touch exit button it quits application?


    EDIT: Found it: http://answers.unity3d.com/questions/422187/android-guitexture-touch.html

    now lets back to the actual game, so instantiate food where i touch and make the sphere (micro) to go there and eat it.

    Edit 2: My Xcover's battery gave up, ordered new one from swedish.
     

    Attached Files:

    Last edited: Apr 20, 2014