Question is off-topic or not relevant
change a created transform in a script from another one
i create somthing like that and i need to drag and trop the object in it i was wondering how can i do it when via script i.e without dragging and dropping
Answer by Shamlei · Jan 22, 2016 at 11:34 PM
Hi there :) !
If you want to change any variable in a script from another you first have to access the script by using the GetComponent method, then you can access any variable from the script without having to put the variable public (which is better).
I can show you an example if you don't understand how to do it.
GameObject x = GameObject.Find ("LineRenderer"); x.GetComponent ().enabled = true
so...i have this to ennable the script bit...pls show me an example and THAN$$anonymous$$ YOU
Sure, Script to access code :
using UnityEngine;
using System.Collections;
public class ScriptToAccess : $$anonymous$$onoBehaviour
{
public int Apples { get; set; }
void Start()
{
Apples = 10;
}
}
`
$$anonymous$$ainScript Code :
using UnityEngine;
using System.Collections;
public class PlayerScript : $$anonymous$$onoBehaviour {
public ScriptToAccess OtherScript { get; set; }
public GameObject GameObjectToFind { get; set; }
void Start()
{
GameObjectToFind = GameObject.Find("TestGameObject");
OtherScript = GameObjectToFind.GetComponent<ScriptToAccess>();
Debug.Log(OtherScript.Apples);
}
}
thank you....but....i dont need apple to equal to an number...i need it to be equal to a gameobject like a sphere for example.
Follow this Question
Related Questions
FormatException: Input string was not in the correct format 0 Answers
Scripting Errors 1 Answer
I want my script to wait 2 seconds before continue in a condition, in update, using C# 2 Answers
error CS0120: An object reference is required to access non-static member 1 Answer
Touch Force on 3D Object 2 Answers