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 /
  • Help Room /
avatar image
0
Question by KalleManuel · Oct 31, 2020 at 12:17 PM · transform.positionmove an objectmovetowards

Why does my cube not move?

I thinking I'm doing something simple here, that I understand, but it don't work. And I've been trying for days.

I have a button with a letter in a cube. When the button is clicked it changes color and the cube sinks in to the wall.

I've tried a tons of different code variants - placing it in different places in the script, using bools, ieumerators , .moveToward .translate etc. It changes color - but it wont move. I'm not a pro at all but I know that atleast some of my tries should work so I'm thinking its something else. Probarbly something pretty simple that I forgot and can't find. I do wan't the cube to move slowly into the wall - In this last try, showed in the script. I just tried to change the position, just to see if it would happen - but no. It printes Klick (click in swedish) so the bool and if statement works.

I'm doing it this way, and not with animation, because when this button work I want to duplicate it and do the whole alphabet placing letters on different positions on the x and y axis. My plan is to use the same script on them all and not do 21 different animations.

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class AnimateButton : MonoBehaviour
 
 
 {
     // Letterboxes
 
     
     public Material newMat1;
     public Material newMat2;
    
 
     public float speed = 0.5f;
     public float currentX;
     public float currentY;
     public Vector3 target;
  
 
     public GameObject cube;
     public GameController2 foundALetter;
 
     public Text buttonText;
     public string buttonTextToString;
     public bool isClicked = false;
     public Button button;
   
 
     // Start is called before the first frame update
     void Start()
     {
 
    
         currentX = gameObject.transform.position.x;
         currentY = gameObject.transform.position.y;
         target = new Vector3(currentX, currentY, -42);
         
 
     }
 
     // Update is called once per frame
     void Update()
     {
         if (isClicked == true)
             print("klick");
         {
             transform.position = new Vector3(currentX, currentY, -42f);
             isClicked = false;
              // StartCoroutine(moveTo(new Vector3(currentX, currentY, -42f)));
         }
     }
 
     public void AnimateTheButton()
     {
         isClicked = true;
         // transform.localPosition= Vector3.MoveTowards(transform.position, target, Time.deltaTime * speed);
         //StartCoroutine(moveTo(target));
        //aAnim.SetBool("isPressed", true);
 
         if (foundALetter.foundLetter == true)
         {
             cube.GetComponent<MeshRenderer>().material = newMat1;
            
         }
 
         else if (foundALetter.foundLetter == false)
         {
             cube.GetComponent<MeshRenderer>().material = newMat2;
         }
         
     }
 
     /*IEnumerator moveTo(Vector3 pos)
     {
         transform.position = Vector3.MoveTowards(transform.position, pos, speed * Time.deltaTime);
         yield return null;   
     }  */
 }
 


skarmavbild-2020-10-31-kl-130542.jpg (497.0 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

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

211 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 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 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 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 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 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 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 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 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 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

Changing transform position - from instantaneous to smooth - not sure how. 0 Answers

How to move more than one object together at a time? 1 Answer

Javascript Script for Object Follow? 0 Answers

Move Character to touched Position 2D (Without RigidBody and Animated Movement) 1 Answer

lerp works on (-6.5/y/z) but not on (+6.5/y/z) 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