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 Tommy · Apr 28, 2011 at 08:20 AM · raycastimagewwwbce0005

Show image depending on RaycastHit.

Hey! I'm trying to get a path depending on wich object that is selected (Using raycast). Here's the code that I got so far, maybe it'll explain what I'm trying to do.

var customSkinTwo : GUISkin; var istrue = false; var vag : System.IO.Path; var objektnamn : String;

static var Player1 : String; //Gets filepath+filename from another script.

var theFullPath : String; var thePath : String;

public var www : WWW; function SetImg() { yield; var vag = theFullPath; var www = new WWW (vag); yield www; istrue = true; icon = www.texture; }

function Update () { if ( Input.GetMouseButtonDown(1) ) { var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit, 1000.0)) { objektnamn = hit.collider.gameObject.name; } }

thePath = this.gameObject.name; theFullPath = "file:///"+thePath;

if (objektnamn == this.gameObject.name) { SetImg(); }

}

function OnGUI () {

 if (istrue) {
      GUI.skin = customSkinTwo;
      GUI.Box (Rect (10,225, 100, 50), icon);
      }

}

So, the problem is that theFullPath becomes "file:///Player1" obviously. I want to make it "file:///the_path_that_Player1_var_contains", how to? (Assume that "Player1" is selected using the raycast.)

New code:

function Update () { if ( Input.GetMouseButtonDown(1) ) { var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit, 1000.0)) { //Debug.Log(hit.collider.gameObject.name); objektnamn = hit.collider.gameObject.name; } }

 obj = GameObject.Find(objektnamn);
 Debug.Log("file:///" + eval( obj.name )); //<--- Line 41.
 theFullPath = "file:///" + eval(obj.name);

if (objektnamn == this.gameObject.name) { SetImg(); } }

Error for new code:

CompilationErrorsException: script(1,9): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown identifier: 'lvl2'.

UnityScript.Scripting.Evaluator.DoCompile () UnityScript.Scripting.Evaluator.CompileScript () UnityScript.Scripting.Evaluator.Run () UnityScript.Scripting.Evaluator.Eval (UnityScript.Scripting.EvaluationContext context, System.String code) PictureShow.Update () (at Assets/Scripts/PictureShow.js:41)

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 Joshua · Apr 28, 2011 at 02:24 PM 0
Share

How does Player1 contain this path? Is it part of it's name? Is it stored in a script attached to the GameObject? If it's the latter change thePath = this.gameObject.name to this.gameObject.GetComponent("name_of_script_that_contains_path_and_is_attached_to_player1").path

avatar image Tommy · Apr 30, 2011 at 11:02 AM 0
Share

It's get the path using a filebrowser. The var contains the path.

avatar image Tommy · Apr 30, 2011 at 11:34 AM 0
Share

Also, it's not attached to the same gameobject as the script above. It's a string.

2 Replies

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

Answer by Santa · May 02, 2011 at 11:18 AM

As far as I understand this should work:

static var Player1 : String = "some_path";

function Update () { var obj : GameObject = GameObject.Find("Player1"); Debug.Log("file:///" + eval( obj.name )); }

Comment
Add comment · Show 3 · 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 Tommy · May 02, 2011 at 02:53 PM 0
Share

It's work, kinda. Iv'e edited it a lil' bit, problem is that, when GameObject.Find("Player1"); is GameObject.Find("Player1-lvl2"); ins$$anonymous$$d, i get the following error:

CompilationErrorsException: script(1,9): BCE0005: Boo.Lang.Compiler.CompilerError: $$anonymous$$ identifier: 'lvl2'.

I'll post the code that i'm using in the question.

avatar image Tommy · May 02, 2011 at 02:58 PM 0
Share

$$anonymous$$aybe i can't use "-" in the object name?

avatar image Santa · May 02, 2011 at 03:06 PM 1
Share

You can't use "-" in variable name. So you must name objects only with variable na$$anonymous$$g rules (without spaces, '.', '+', '-' etc).

avatar image
0

Answer by efge · May 02, 2011 at 10:52 AM

If your object names and path names are Strings you could use standard String operators(?).

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

No one has followed this question yet.

Related Questions

!texture.texture error 0 Answers

Finding size of images imported at runtime 2 Answers

Detect WWW Image bitmap dimensions? 2 Answers

Loading a higher resolution image into Unity than what is supported 0 Answers

How do you download image to UI.Image? 4 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