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)