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 London243 · Jun 09, 2014 at 07:56 PM · getcomponentguitexturesendmessagemove object

Move a cube from GUITexture. Is not working. Where is my mistake

Hello

I really hope someone can help me in this since I am working already two days but without any result.

What I' am trying to achieve in this instance is to move a GameObject when a GUI Texture is touch on a Iphone. The GameObject to be moved is named Cube in the hierarchy The Game Object Cube has a Script named Left that supposedly when "call it " from the GUITexture made the Cube move left.

I hope is clear I want to "activated" the script in the Game Object from the Guitexture. I try to use send message but without any joy as well so I am using GetComponent

This is the script "inside" the left GUITexture.

using UnityEngine; using System.Collections;

public class Player : MonoBehaviour { public GameObject Cube;//GameObject to be moved private Left left;//script inside the gameobject cube so it can move left when call it from the GUItexture

void Awake() { left = Cube.GetComponent (); }

void Start() { Cube = GameObject.Find ("Cube"); }

void Update () {

 //is there a touch on screen 

 if (Input.touches.Length <= 0) 
 {
     //if there is no touches on the screen  the this code

     return;
 } 



 else // if there is a touch

 {

     //loop through all the touches on the screeen 

     for(int i = 0 ; i < Input.touchCount; i++)
     {
         //execute this code for current touch (i) on the screeen 

         if(this.guiTexture.HitTest(Input.GetTouch(i).position))
            {
             //if current hits our guiTecture, run this code
             if(Input.GetTouch (i).phase == TouchPhase.Began)

                 //move the cube


                 Cube.GetComponent<Left> ();


             }
             {
             if(Input.GetTouch (i).phase == TouchPhase.Ended)


                                Return; 
             {
             if(Input.GetTouch(i).phase == TouchPhase.Stationary);

             //if current finger is stationary  run this code

             Cube.GetComponent<Left> ();
             }



    }





 }

}
}

This is the Script named Left that is "inside" the GameObject

public class Left : MonoBehaviour {

// Use this for initialization void Start () {

}

// Update is called once per frame void OnMousedown () { transform.position += Vector3.left * Time.deltaTime;

} }

I really HOPE someone can help me

Thank you

CL

Comment
Add comment · Show 3
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 christoph_r · Jun 09, 2014 at 09:07 PM 0
Share

Okay, so your Left $$anonymous$$onoBehaviour is deactivated by default? In that case, change Cube.GetComponent (); to Cube.GetComponent().enabled = true;. That should do the trick.

avatar image London243 · Jun 09, 2014 at 09:58 PM 0
Share

Thank you I will try it and will let you know Cheers

avatar image London243 · Jun 11, 2014 at 09:48 AM 0
Share

sorry but i doesn't work.

I don't know what to do

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

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

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

more pragma strict getComponent and SendMessage problems 0 Answers

GetComponent for all enemies 1 Answer

pickup weapon with GetComponent 0 Answers

I am trying to send a 2D texture to my first person controller to display on the GUI 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