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 08, 2015 at 01:56 AM · android2dgameobjectobjectmobile

Expand Object On Touch? Someone please help me

Hello. Part of my game needs a script that, when the object specified is touched, will expand the object on the X and Y axis. I made the following script hoping that it would work as I had wished, but unfortunately it doesn't work. I was hoping that posting this on here would let someone help me. But the past couple posts just don't get responses. The game is 2D and for the Android. Even if this seems quite easy to most of you, due to my lack of knowledge with Scripting and Game Creation it isn't for me, so all help is very appreciated.

 pragma strict
   public var localScale: Vector3;
   
   function Update() {
   
     for (var i = 0; i < Input.touchCount; ++i) {
         if (Input.GetTouch(i).phase == TouchPhase.Began)
             transform.localScale += new Vector3(0.1F, 0, 0);
             }
      }
            

   

I'd just like to say. This is about my 3d or 4th time trying to receive an answer. I am in need of an answer to the problem as soon as possible. As said, all help is appreciated.

Comment
Add comment · Show 1
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 curiouspers · Mar 08, 2015 at 12:13 PM 0
Share

@SUPPEAR check the updated answer

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by curiouspers · Mar 08, 2015 at 11:02 AM

Ok, you can use this method:

 private bool selected = false;
 private Vector3 defaultSize = Vector3.one;
 public Vector3 selectedSize = new Vector3(0.1f, 0.1f, 0);

 void OnMouseDown() {
     Debug.Log("click down on "+name);
     //if (GM.isGameOver || GM.isPaused)  //in case you don't want to select when game is paused
     //    return;
     selected = true;
 }

 void Update(){
     if (selected) {
         //sRenderer.color = new Color (1f, 1f, 1f, 0.5f);     // if you need to change color
         transform.localScale = defaultSize + selectedSize; 
         //col.size = defaultSize * 1f/transform.localScale;            // if you need to keep your collider size
     } else {
         //sRenderer.color = new Color(1f,1f,1f,1f);         // if you need to change color
         transform.localScale = defaultSize;
         //col.size = defaultSize;
     }
 }

It's C#, but i believe you can translate it to UnityScript if you want, because it's sooo similar. But you might want to use C#. Oh and don't forget to put collider on your object.

But i suggest you considering using mecanim animation for your objects.

EDIT: i looked up through your questions, and now i understand why you can't get answers for your questions and why you are not sattisfied with unityAnswers. It's because you post one question several times, up to 4 times, you really should not do this, and even when you get some answers you do not accept them as coorect, you do not upvote them, you do not comment back what is wrong, or what is right.

To be honest, you are not even rephrase your question, when it's clear that people don't get it right what you want to achieve, in one of four duplicates of this question, you posted this:

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

In this question, there is nothing about this. And this is sucks, because how do you get right answer if you do not ask correctly, and do not specify all the details you want?

Now my answer should be: Why are you not say that earlier? Replace Update function with this:

 void Update(){
     if (selected) {
         transform.localScale += selectedSize; 
     } else {
         transform.localScale = defaultSize;
     }
 }

...and you should be good to go. But i not sure that this is what you wanted.

And i got answer for you on how to get proper and fast answers:

As a first step i would suggest you watching this short video, that always been on the right side of this page.

Then try to EDIT your existing question, if you got any new details, instead of posting the duplicate, try to be as more specific as you can, add more details, add what you're already tried, what search you already made (and use search in first place before posting any question!), add pictures and videos if you have some, or even photo of your mockup on paper, if you think this will make thing simpler to understand. Because nobody knows what exactly do you have in your scene, or project, or your head. It's clear for you what you want to be done, so you must ask question in a way that it would be clear what you want to be done for anybody who reads your question.

Then go to your profile here on unityAnswers, by clicking on your nickname at the right top corner of this page, and follow this steps: Try to give a proper comment on all comments and answers you have. Try to upvote and select as correct answers when people was correct, and if they was not correct say them why they was not correct, maybe you're not provided some detail? Make this with every question you ever ask.

This will make people more friendly to you and you'll be good example for everybody, and as a bonus you will get answers more quickly! And maybe someday you can give good answers for others to share your knowledge!

I don't know if you have rights to delete or close duplicate questions, if you have the right to delete your own questions, delete every one of duplicate that has not been answered. This will make moderators life easier, and they will live thankfull and happy lives.

Then go to this page, and to tutorials section, if you follow at least some of them, great part of your questions will be solved, and you level up your skills several times for free!

On that same page you got documentation page that will vanish another part of your questions, and live training that is soooo awesome.

Then you

PS: i'm so so sorry for my poor english.

Comment
Add comment · Show 4 · 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 09, 2015 at 09:36 PM 0
Share

Thank you for responding. I will look into the links you have sent me. I've used the script you given, but it says this as an error. Assets/Standard Assets ($$anonymous$$obile)/Textures/Exapdn.cs(6,16): error CS0116: A namespace can only contain types and namespace declarations

avatar image SUPPEAR · Mar 09, 2015 at 10:18 PM 0
Share

I'd like to say that I have found a solution to this problem.

avatar image curiouspers · Mar 10, 2015 at 10:45 AM 0
Share

@SUPPEAR Glad to hear that, can you mark my answer as correct? It's right below thumbs down button.

avatar image SUPPEAR · Mar 10, 2015 at 11:22 PM 0
Share

I mean I could but the solution was one different from yours..

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