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 Snownebula · May 24, 2015 at 09:52 PM · setactiveenabled

How can I enable an object in js?

An instance of type 'UnityEngine.GameObject' is required to access non static member 'SetActive'. This is the code that I am trying to get to work: ship = GameObject.SetActive(true); I am trying to enable an object in js from a script not attached to that object. Is this even possible?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Sketch_Kidd · May 24, 2015 at 10:34 PM

It is possible try

 var yourGameObject = GameObject.Find('your gameobject');
 
 yourGameObject.SetActive(true);

it would be easier to solve if you post an example code, personally I prefer C# but this can be achieved in both unityScript and C#

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

Answer by Snownebula · May 25, 2015 at 12:10 AM

 var target : Transform;
 var distance = 3.0;
 var xSpeed = 200.0;
 var ySpeed = 200.0;
 var yMinLimit = -20.0;
 var yMaxLimit = 80.0;
 var mLimit = 0.0;
 public var ship;
 public var shipb;
 public var ship2 : GameObject;
 
 private var rightclicked = null;
 private var x = 0.0;
 private var y = 0.0;
 var minDistance = 1.0;
 var maxDistance = 20000.0;
 
 public var s1 : boolean = false;
 public var s2 : boolean = false;
 public var s3 : boolean = false;
 public var s4 : boolean = false;
 
 @script AddComponentMenu("Camera-Control/Mouse Orbit")
 
 function Start () {
     var angles = transform.eulerAngles;
     x = angles.y;
     y = angles.x;
     //Debug.Log("Hit 0.");
     //CheckActive1();
     //Debug.Log("Hit 6.");
 
     // Make the rigid body not change rotation
        if (GetComponent.<Rigidbody>())
         GetComponent.<Rigidbody>().freezeRotation = true;
 }
 
 function Update () {
         CheckActive1();
         var rotation = Quaternion.Euler(y, x, 0);
         var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
         transform.position = position;
             distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel")* mLimit, minDistance, maxDistance);
             //distance += -300.0f*Input.GetAxis ("Mouse ScrollWheel")*5, minDistance, maxDistance);
             //")*Time.deltaTime;
         if(distance < minDistance)
             distance = minDistance;
         else
         if(distance > maxDistance)
             distance = maxDistance;
         if (Input.GetMouseButtonDown(1)) {
             rightclicked = true;
         }
         if (Input.GetMouseButtonUp(1)) {
             rightclicked = false;
         }
 }
 
 function CheckActive1 () {
     Debug.Log("Hit 0.1.");
     if (s1 == true) {
         //GameObject.FindWithTag("t1").Transform.SetActive;
             Debug.Log("Hit 1.");
             //ship = GameObject.SetActive(true).FindWithTag("t1");
             //Debug.Log("Hit 1.3.");
             ship2 = GameObject.FindGameObjectWithTag("t1").SetActive(true);
             //var ship2 = GameObject.FindWithTag("t1");
             //ship2 = enabled(true);
             target = ship2.transform;
             //ship = GameObject.FindWithTag("t1").transform;
             //Debug.Log("Hit 2.");
             //target = ship;
             Debug.Log("Hit 3.");
             mLimit = 1000;
             Debug.Log("Hit 4.");
             minDistance = 7500;
             Debug.Log("Hit 5.");
             distance = 10000;
             maxDistance = 20000;
             s1 = false;
             //}
         }
     else if (s2 == true) {
         //GameObject.FindWithTag("t2").Transform.SetActive;
             Debug.Log("Hit 1b.");
             ship = GameObject.FindWithTag("t2").enabled = true;
             Debug.Log("Hit 1.2b");
             ship = GameObject.FindWithTag("t2").transform;
             Debug.Log("Hit 2b.");
             target = ship;
             Debug.Log("Ship: " + ship);
             mLimit = 1;
             Debug.Log("Mouse Limit: " + mLimit);
             distance = 3;
             Debug.Log("Camera Distance: " + distance);
             minDistance = 2.30;
             Debug.Log("Min Distance: " + minDistance);
             maxDistance = 60;
             Debug.Log("Max Distance: " + maxDistance);
             s2 = false;
             //}
         }
     }
 
 function LateUpdate () {
      if (target && rightclicked == true) {
         x += Input.GetAxis("Mouse X") * xSpeed * 0.01;
         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.01;
          
          y = ClampAngle(y, yMinLimit, yMaxLimit);
                 
         var rotation = Quaternion.Euler(y, x, 0);
         var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
         
         transform.rotation = rotation;
         transform.position = position;
         }
 }
 
 static function ClampAngle (angle : float, min : float, max : float) {
     if (angle < -360)
         angle += 360;
     if (angle > 360)
         angle -= 360;
     return Mathf.Clamp (angle, min, max);
 }
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
avatar image
0

Answer by Hexer · May 25, 2015 at 12:55 AM

As for so far I know, You cannot check (enable) your gameObject when it is unchecked (disabled in the hierarchy).

Try a different approach like disabling a component from that gameObject to get the desired effect.

EDIT : As for Sketch_Kidd answer, that only works when you try it the other way. (when you try to disable the gameObject)

Comment
Add comment · Show 1 · 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 Snownebula · May 25, 2015 at 08:44 AM 0
Share

What about making active or inactive?

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

21 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

Related Questions

PlayerCamera.AudioListener.enabled = false; will not work 1 Answer

physics.OverlapSphere colliders 1 Answer

sync renderer.enabled or SetActive() over network? 0 Answers

sync renderer.enabled or SetActive() over network? 2 Answers

works with gameObject but not with Image SetActive vs Enabled 1 Answer


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