Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by SoloFish42 · Dec 19, 2016 at 08:42 PM · scripting problemmovement scriptlistsqueuemechanics

Temporary GameObject Movement

PLEASE READ ALL OF THE INFO AS IT IS IMPORTANT THAT YOU KNOW ALL THE INFO ABOUT THE SCRIPT FIRST!

Hello everyone, I am currently in the process of making a small unity game all alone. Right now there is a big bottleneck in my project which if I solve, the game will be pretty much 99% done. This has been bothering me for a week now.

It is about a script which makes the lowest of multiple objects on screen horizontally controllable, sort of like tetris where the lowest group of blocks is always controllable and as soon as the lowest controllable objects disappears, the next lowest one turns into the controllable and so on. I havent tried making a queue script, since I am unexperienced when it comes to . But, here is a script that I compiled with the help of several reddit users, which still seems to be not working.

Note that no compiler errors appear, but the functions just dont work...

This script here has a movement mechanic (which works fine whenever I manually select the lowest object), a spawn mechanic (which doesnt work) and a mechanic that is supposed to track the lowest object on the screen out of the listed ones (doesnt work). the part where it says redbrix, bluebrix, these are all different gameobjects that are supposed to be moveable (the lowest one on screen is the moveable one), the script is supposed to track all these 5 objects and define which one is the lowest on screen and add it to the "currentObject", but that just doesnt work... this script is added to the mainCamera.

SCRIPT STARTS HERE

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class controllerList : MonoBehaviour { public List ControlObjects = new List(); // Tracks all the objects current on screen public GameObject CurrentObject; // Tracks the current controlled object

 // References to the objects to instantiate
 [SerializeField] private GameObject redbrix;
 [SerializeField] private GameObject bluebrix;
 [SerializeField] private GameObject yellowbrix;
 [SerializeField] private GameObject greenbrix;
 [SerializeField] private GameObject rainbowbrix;

 // "delay" the amount of delay in seconds between the gameObjects spawning
 [SerializeField] private float delay = 1f;

 void Start()
 {
     InvokeRepeating("Spawn", delay, delay);
 }

 public void Update()
 {
     // Input controls to move the CurrentObject
     if (Input.GetKeyDown(KeyCode.A))
     {
         Vector3 position = CurrentObject.transform.position;
         position.x--;
         CurrentObject.transform.position = position;
     }

     if (Input.GetKeyDown(KeyCode.D))
     {
         Vector3 position = CurrentObject.transform.position;
         position.x++;
         CurrentObject.transform.position = position;
     }
 }


 /*---------------------------
 // Spawns a new brix at the spawn point
 // -- brixType: the type of brix you want to spawn
 -----------------------------*/
 public void SpawnNewObject (GameObject CurrentObject)
 {
     // Create the new brix 
     GameObject newBrix = Instantiate(CurrentObject, new Vector3(Random.Range(-8, 8), 6, 0), Quaternion.identity) as GameObject;

     // Add the new brix to the list of objects
     ControlObjects.Add(newBrix);
 }

 
 /*---------------------------
 // Will find the lowest brix in the scene and set it to CurrentObject    
 -----------------------------*/
 public void GetLowestObject()
 {
     // This temporary variable will track the lowest object, set to the first object by default
     GameObject lowestObject = ControlObjects[0];

     // Now loop through the rest and check if it's lower
     for (int i = 1; i < ControlObjects.Count; i++)
     {
         if (ControlObjects[i].transform.position.y < lowestObject.transform.position.y)
             lowestObject = ControlObjects[i];
     }
 }


 /*---------------------------
 // Call this when you want the current controlled object to be destroyed
 -----------------------------*/
 //public void DestroyCurrentObject()
 //{
   //  ControlObjects.Remove(CurrentObject);
   //  Destroy(CurrentObject);
 //}

}

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How can i make my character jump and slide on command? 0 Answers

Movement Code not working 2 Answers

Why wont my character stop moving when it collides with the obstacles?,Why doesn't my movement script stop? 0 Answers

How to I put a speed limit on my character's movement? 1 Answer


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