Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Feb 11, 2016 at 07:00 PM by Phantom01 for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Phantom01 · Jan 22, 2016 at 10:57 PM · c#scripting problemnoobstuck

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

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 Phantom01 · Jan 22, 2016 at 10:58 PM 0
Share

public Transform Origin;

1 Reply

  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 6 · 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 Phantom01 · Jan 22, 2016 at 11:36 PM 0
Share

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

avatar image Phantom01 · Jan 22, 2016 at 11:50 PM 0
Share

pls anwer Q_Q

avatar image Shamlei Phantom01 · Jan 23, 2016 at 12:09 AM 0
Share

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);
 
     }
 
 }
 



avatar image Phantom01 Shamlei · Jan 23, 2016 at 12:16 AM 0
Share

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.

Show more comments
Show more comments

Follow this Question

Answers Answers and Comments

67 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 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 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 avatar image

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


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