Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jun 01, 2014 at 12:34 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ObeliskEntertainment · May 31, 2014 at 11:59 PM · movementarrayinstantiated

Control when instantiated objects can move.

Hello. I am making a clone of the "Don't touch the white tile game" and it's all running smoothly, but I seem to be stuck on trying to limit which "black" tile moves them all down. I want it to be only when I touch the black block on the bottom that executes the command to move them all.

Currently when I touch any black block it'll move it down. I need some type of method to prevent anything higher than 0f cannot execute the "move" command. using UnityEngine; using System.Collections; using System.Collections.Generic;

 public class Movement : MonoBehaviour {
     public Instantiate bringInstantiate = new global::Instantiate ();
     private SoundFX importSound = new SoundFX ();
     private ScoreLog importScore = new ScoreLog();
     private string importScorelog = ScoreLog.currentScore.ToString();
     private int touchCounter;
     private GameObject[] grabBlackClonesArray;
     private Vector3[] vectors = new Vector3[4];
     private Vector3 selected;
     private int randomNumber;
     private bool correctTouch;
 
 
     public void Awake()
     {
                 //Create vector Positions
                 this.vectors [0] = new Vector3 (0f, 3.75f, -1.5f);
                 this.vectors [1] = new Vector3 (1.25f, 3.75f, -1.5f);
                 this.vectors [2] = new Vector3 (2.5f, 3.75f, -1.5f);
                 this.vectors [3] = new Vector3 (3.75f, 3.75f, -1.5f);
 
         }
 
     
     void Start()
     {
         //We set the array to have slots 0,1,2,3 (total of 4)
         grabBlackClonesArray = new GameObject[5];
 
         //We debug to see if the position 0 is not null
         Debug.Log (grabBlackClonesArray[0]);
 
 
 
     }
 
 
     
 
     
     
     
     void Update() {
 
         int randomNumber = Random.Range (0, 4);
         this.selected = this.vectors [randomNumber];
 
 
 
 
 
         importScorelog = ScoreLog.currentScore.ToString();
 
         //Vector3[] newlocation = 
 
         //We finally set grabBlackClonesArray and fill it up with all objects
         //with the tag "BlackTile"
 
         grabBlackClonesArray = GameObject.FindGameObjectsWithTag("BlackTile");
 
         //We check to see if it is true
 
         //To make sure that the movement is only done once we put it in a loop
         //remember we are in the Update method..it's called every frame
         if(grabBlackClonesArray[0].transform.position.y <= -1.25f) {
             Debug.Log ("clicked and ran <= 0.f");
             grabBlackClonesArray[0].transform.position = selected;
         }
         if(grabBlackClonesArray[1].transform.position.y <= -1.25f) {
             Debug.Log ("clicked and ran <= 0.f");
             grabBlackClonesArray[1].transform.position = selected;
         }
         if(grabBlackClonesArray[2].transform.position.y <= -1.25f) {
             Debug.Log ("clicked and ran <= 0.f");
             grabBlackClonesArray[2].transform.position = selected;
         }
         if(grabBlackClonesArray[3].transform.position.y <= -1.25f) {
             Debug.Log ("clicked and ran <= 0.f");
             grabBlackClonesArray[3].transform.position = selected;
         }
         //We need to grab the touch on Android Devices
         if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began || Input.GetKeyDown ("k")) {
 
             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             RaycastHit hit;
 
         
             if(Physics.Raycast (ray,out hit) && hit.collider.gameObject.name == "BlackTile(Clone)")
             {
                 importScore.Score ();
                 importSound.SoundFXs();
                 correctTouch = true;
 
 
                     grabBlackClonesArray [1].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [0].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [2].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [3].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [4].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                 
         
             
         
             }
 
             else if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) {
                 touchCounter++;
                 if(touchCounter == 1) {
 
                     Application.LoadLevel(2);
                     touchCounter--;
 
 
                 }
 
             }
    }
 
   }
 
     void OnGUI() {
         GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(4, 2, 1));
         GUI.Label (new Rect (9,125,255,255), (importScorelog));
 
         }
  }


///////////////////////////// alt text

blackgame.png (8.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by ObeliskEntertainment · Jun 01, 2014 at 12:16 AM

Wow, I was quick to solve my own problem. I just needed to put a if statement with the movement command. Then after that I needed to use a raycast to detect which object was hit and check it's location.

 if(grabBlackClonesArray[3].transform.position.y == 0f) {
                     if(Physics.Raycast (ray,out hit) && hit.collider.gameObject.transform.position.y == 0f) {
                     grabBlackClonesArray [1].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [0].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [2].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [3].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     grabBlackClonesArray [4].transform.position -= new Vector3 (0.0f, 1.25f, 0.0f);
                     }
                 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Movement through an array over time 2 Answers

Instantiated object isnt moving 1 Answer

Problem with moving objects in array? 2 Answers

Move continuously through array of Vectors 1 Answer

NullRefenceException Using Arrays 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges