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 /
avatar image
0
Question by RealStarlightStudios · May 18, 2018 at 09:11 AM · javascriptgameobject4.6enableslenderman

How do i make a script that makes the gameobject enabled,

So i just got a kit from MasterDevelopers and I'm trying to edit a script when if you collect 1 page, Slender man will appear in the woods. (The game object will be enabled) I tried other solutions but they don't work. Does anyone have a solution?

Code: JavaScript Version: 4.6

/// created by MasterDevelopers /// #pragma strict @script RequireComponent( AudioSource )

 var papers : int = 0;
 var papersToWin : int = 8;
 var papersToSlender : int = 1;
 var distanceToPaper : float = 2.5;
  
 public var paperPickup : AudioClip;
  
 var theEnemy : EnemyScript;
  
  
  
  
 function Start()
 {
 Screen.lockCursor = false;
  
 // find and store a reference to the enemy script (to reduce distance after each paper is collected)
 if ( theEnemy == null )
 {
 theEnemy = GameObject.Find( "Enemy" ).GetComponent( EnemyScript );
 }
 }
  
  
 function Update()
 {
 //if ( Input.GetMouseButtonUp(0) ) // use E in editor as LockCursor breaks with left mouseclick
 if ( Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.E) )
 {
 //var ray = Camera.main.ScreenPointToRay( Input.mousePosition ); // always cast ray from center of screen
 var ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );
 var hit : RaycastHit;
 if ( Physics.Raycast( ray, hit, distanceToPaper ) )
 {
 //if ( hit.collider.gameObject.tag == "Paper" )
 if ( hit.collider.gameObject.name == "Paper" )
 {
 papers += 1;
 //Debug.Log( "A paper was picked up. Total papers = " + papers );
  
 audio.PlayClipAtPoint( paperPickup, transform.position );
  
 Destroy( hit.collider.gameObject );
  
 // make enemy follow closer
 theEnemy.ReduceDistance();
 }
 }
 }
 }
  
  
 function OnGUI()
 {
 if ( papers < papersToWin )
 {
 
 }
 else
 {
 
 Application.LoadLevel( "Main Menu" );
 {
 if ( papers < papersToSlender )
 {
 GameObject.GetComponent(GameObject);
 GameObject.transform.active = true;
 }
 else
 {
 
 }
 }
 }
 }
Comment
Add comment · Show 2
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 RealStarlightStudios · May 18, 2018 at 09:13 AM 0
Share

whoops, i made a bit of mistake. don't know if i could fix it

avatar image RealStarlightStudios RealStarlightStudios · May 18, 2018 at 09:14 AM 0
Share

nvm I fixed it

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mhogan256 · May 18, 2018 at 10:50 AM

C# example

for components CameraHolder.SetActive(true);

for gameobjects: charCanvas.GetComponent().enabled = true;

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 RealStarlightStudios · May 18, 2018 at 11:59 AM 0
Share

but what about the javascript example?

avatar image
0

Answer by elandant · May 18, 2018 at 12:17 PM

What mhogan256 said still applies for JavaScript. It would be GameObject.SetActive(true);

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 RealStarlightStudios · May 18, 2018 at 12:23 PM 0
Share

but when I putted it in it shows an error like this

alt text

error.png (5.3 kB)
avatar image elandant RealStarlightStudios · May 18, 2018 at 01:20 PM 0
Share

Hmm. Do you have a variable for the object you are referencing stored? And are you accessing it directly? Or is it just "GameObject"?

avatar image elandant RealStarlightStudios · May 18, 2018 at 01:25 PM 0
Share

Also could you please attach the line that is causing the error and the variable you have linked to it?

avatar image
0

Answer by NETRIDER · Jun 01, 2018 at 09:15 PM

@RealStarlightStudios thanks for postiing this question on my stream. please check your folder structure, the code for detection you have at function start is where I would look at moving around. some js and cs files need to be placed in specific folders to see one another. I hope I can find a code snippet to share. thanks again!

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

184 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 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 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

how to enable a java script inside a gameobject on press of the space key? 1 Answer

How to rotate one cube from another cube? 1 Answer

Spawning only 1 gameObject 3 Answers

Primary constructor body not allowed????? i don't see whats wrong? 1 Answer

How to make sprite follow gameObject on trigger? 0 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