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 infinitypbr · Jun 24, 2013 at 11:07 PM · gameobjectaccessing scripts

What is wrong with this script? Error connecting with another objects scripts/functions

I have a controller script that figures out what a player is touching on the screen. Then I have a script that moves the lid of a coffin if the player touched it. However, whenever I try any code -- the function intended or even just updating a boolean variable -- there is an error in XCode that breaks the app. For the life of me I can't figure out what is wrong.

I can confirm that without the line that "speaks" to the clickable.js script (Attached to the coffin lid) no errors happen. I can also confirm that the function on clickable.js works perfectly (just tried it with an automated movement after a 5 second delay, worked fine).

Here is my code, any assistance would be wonderful:

controller.js

 function Update () { 
 
 for (var i = 0; i < Input.touchCount; ++i) 
     {
         if (Input.GetTouch(i).phase == TouchPhase.Began)
         {
                 var hitWorld : RaycastHit;
                 var screenPosWorld = Input.GetTouch(i).position;
                 var worldPosWorld = playerCamera.ScreenToWorldPoint(screenPosWorld);
                 var rayWorld : Ray = playerCamera.ScreenPointToRay (Input.GetTouch(i).position);
                 if (Physics.Raycast (rayWorld, hitWorld, 100)) 
                 {
                     var playerClickDistance = Vector3.Distance(hitWorld.collider.gameObject.transform.position, playerObject.transform.position);
                     if (hitWorld.collider.gameObject.tag == "Clickable")
                     {
                         //I BELIEVE THIS LINE BELOW IS THE PROBLEM
                         hitWorld.collider.gameObject.GetComponent(clickable).GotClicked(playerClickDistance);
                     }
                 }
         }
     }
 }

clickable.js

 function GotClicked(playerClickDistance : float)
 {
     if (objectType == "Coffin 1" && playerClickDistance <= playerDistance) { ClickCoffin1(); }
 }
 
 function ClickCoffin1 () {
     var i = 0.0;
     var rate = 1.0 / animationTime;
     while (i < 1.0) {
         i += Time.deltaTime * rate;
         coffinLid.transform.position = Vector3.Lerp(startPosition, endPosition, i);
         coffinLid.transform.eulerAngles = Vector3.Lerp(startRotation, endRotation, i);
         yield; 
     }
 }
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 infinitypbr · Jun 24, 2013 at 11:49 PM 0
Share

The code below works only until access to the other script is needed:

 var player : GameObject = hitWorld.collider.gameObject;
 print ("GameObject Name: " + player.name);
 print ("GameObject Tag: " + player.tag);
 print ("GameObject Variable 'gotClicked': " + player.GetComponent(clickable).gotClicked);

XCode Output:

 GameObject Name: Coffin Lid
 
 GameObject Tag: Clickable
 
 (lldb) 

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by infinitypbr · Jun 25, 2013 at 12:24 AM

I was expecting an answer showing how dumb I am at times, and sure enough: The script I was trying to access was on the parent of Coffin Lid, not on the object, and that is where the problem came from.

Comment
Add comment · 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

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

15 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

Related Questions

Initializing objects with another scripts variables. 1 Answer

Instantiated Object's Scripts not enabled? Not sure why 3 Answers

how to build & populate an array available to all scripts on all objects? 1 Answer

Getting a Script without setting a variable to the script name 1 Answer

Adding an array of scripts to a class 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