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 /
avatar image
0
Question by SUPPEAR · Mar 01, 2015 at 05:02 AM · android2dgameobjectobjectmobile

Transform.LocalScale Script Problem. Please help.

Hello. I'd like to start off by saying that I am very new to Script and creating games, so all help is appreciated. I am trying to create a script that, when a certain object is touched, all objects within the folder would expand (Transform.LocalScale). I can't even figure out how to simply expand an object when it is touched. Just to clarify, when I say expand I mean that when the object is touched once it would continually expand. All help is appreciated.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kowalski042 · Mar 01, 2015 at 07:38 AM

There are tutorials on Unity3d. Search for how to do OnCollision in Unity. That should help you.

Comment
Add comment · Show 1 · 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
avatar image SUPPEAR · Mar 04, 2015 at 04:48 AM 0
Share

OnCollision is not what I want. I want it so that it continually expands when the user touches it once with his finger.

avatar image
0

Answer by skylem · Mar 01, 2015 at 05:57 AM

You've not provided the language in which your attempting this, heres a c# solution. heres a rough idea of how to achieve this, firstly your going to want a method to detect whether the object has been clicked i think the simplest way of doing this is with MouseOver/MouseExit functions

the following script should be placed upon the object your clicking

 using UnityEngine;
 using System.Collections;
 
 public class AddUnitToSelection : MonoBehaviour {
 
     public bool hover;
     GameObject gameController;
     // Use this for initialization
     void Start () {
         gameController = GameObject.FindGameObjectWithTag ("GameController");
     }
     
     // Update is called once per frame
     void Update () {
         if(hover && Input.GetButtonDown("Fire1")) {
             gameController.GetComponent<SelectedUnit>().SetUnit(gameObject.transform);
         }
     }
     void OnMouseOver() {
         hover = true;
     }
     void OnMouseExit() {
         hover = false;
     }
 }

this script can be placed anywhere in the scene but be sure to Tag the object as GameController.

     using UnityEngine;
     using System.Collections;
     
     public class SelectedUnit : MonoBehaviour {
     
     
         public Transform SelectedUnit;
         // Use this for initialization
         void Start () {
         
         }
         
         // Update is called once per frame
         void Update () {
         // here is where we will set the scale of the object we clicked before removing the selection
         if(SelectedUnit != null) {
           SelectedUnit.localScale = SelectedUnit.localScale * 2; // double the size
           SelectedUnit = null; // Empty the selection
 }
         }
         // this is where set the selected unit based off the object we clicked, Object we clicked
         // Must have a Collider aswell as the first script attatched to it.
         public void SetUnit(Transform tr) {
             SelectedUnit = tr;
         }
     }


if you need more information on how they work just ask.

Comment
Add comment · Show 2 · 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
avatar image SUPPEAR · Mar 01, 2015 at 07:43 AM 0
Share

First off, I thank you for replying. I have quickly skimmed through and wanted to make sure that this would work on the android, as I am making it on the android.

avatar image skylem · Mar 01, 2015 at 07:59 AM 0
Share

certainly it would however u would need to substitute the Input.GetButton for a Touch Input, see the documentation on Input.GetTouch

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

22 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 avatar image avatar image

Related Questions

Transform.localPosition Script Problem. 3 Answers

Collision On Object Error. Please help. 1 Answer

Problem creating a script to destroy object on collision. 1 Answer

Transform.localPosition Scripting Problem. 1 Answer

Duplication Problem. Please help. 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