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 Barruchi · Oct 20, 2014 at 09:34 PM · animationjavascriptobject

Desactive a object

Hi guys,

I doing a animated background. Basically when the object reaches the position.x is desactived.

But this sprite that i'm working now, don't move. So i need that the animation occur one time, then the objective is desactived.

I'm using the code below for now...

Obs: Tamanho = SCALE

Thanks!

 var speed : float;
 var bloco : GameObject;
 var maxposition : float;
 var maxScale: int;
 var minScale: int;
 var tamanho: float;
 
 
 function Start () {
 
 }
 
 function Update () {
     tamanho = Random.Range(maxScale, minScale);
     transform.localScale = new Vector3 (tamanho, tamanho,0);
     transform.position += new Vector3(speed, 0, 0) * Time.deltaTime;
         if (transform.position.x > maxposition)
             {
             bloco.SetActive(false);
             }
             
         }
Comment
Add comment · Show 2
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 Chapi · Oct 23, 2014 at 01:11 AM 0
Share

I don't understand what you're trying to do or what the problem is. I believe you want your bloco gameObject to get deactivated when it passes certain coordinate on the x axis, right? If that's the case, whats the problem? Because your code seems fine, despite the fact that transform.localscale moves the object or whatever, the if you stated should work fine.

avatar image Barruchi · Oct 23, 2014 at 04:01 AM 0
Share

Yes it's fine...

But this is just a example that i use in object that really moves.

Now I have a animation that don't move, and I need that he plays once and desactive.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ryujose · Oct 20, 2014 at 09:48 PM

You need to declare the float number "X" maxposition to deactivate GameObject named bloco.

You can declared it on function Start() and set the float number.

You need to declare float and int of speed, maxScale, minScale and tamaño.

Hope it will helpfully to you.

Regards.

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 Barruchi · Oct 22, 2014 at 08:21 PM 0
Share

@Ryujose

Actually this code is already used for objects that moves on the screen.

But this object don't move. I need to know can I desactive him, after the animation play just once.

avatar image Ryujose · Oct 23, 2014 at 12:38 AM 0
Share

Try to declare a float number for "maxposition" because you're telling that if your object moves on position X when reach the max position GameObject will be deactivated.

If you don't move it then this script don't Works on it. Because you can't move 0X to 0X.

You should try to implement those methods and change the script for this animation.

http://docs.unity3d.com/ScriptReference/Animation.html

avatar image Barruchi · Oct 23, 2014 at 03:30 AM 0
Share

@Ryujose

Yeah, and this is what i'm doing for others sprites...

That was just a example.

I'm trying to use the Animation, but, How I can desactive the object when he ends the animation?

avatar image Ryujose · Oct 23, 2014 at 02:46 PM 0
Share

There are 2 ways that I know.

1) When the animation stop, deactivate the GameObject similar like the process of the script you post here.

2) When the animation stop, make "renderer.enabled = false" this makes the GameObject invisible. Check this documentation.

http://docs.unity3d.com/ScriptReference/Renderer-enabled.html

I think this should Works.

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

Current speed of an object? 5 Answers

Animation play 1 Answer

Why isn't my animation being played? 0 Answers

Changing number of frames in uvAnimationTileX 0 Answers

Using arrays to randomly select an object 0 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