Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 kemnet · Feb 02, 2021 at 11:02 PM · gameobjectgetcomponentcollision2d

Difficulty setting script on gameObject from another script.

Greetings all

I have a bug in my game that I hope I can be assisted with.

I have a game object ( my player) and an objects that supposed to stun my player when they collide.( cant move or job) Please see my script below.

 public class FallingObjectControl : MonoBehaviour
 {
 //Get the Character
 public GameObject playerObject;

 public Rigidbody2D _rigidbody;
 private bool Stunned;
 public float StunnedFor = 5.0f;

 private CharacterHorizontalMovement mainChar;
 private bool AbilityPerScript;
 // Use this for initialization
 void Start()
 {
 }

 void FixedUpdate()
 {
     if (Stunned)
     {
         Debug.Log("Stunned");
         //  HandleStun();
         StartCoroutine(HandleStun());

     }
 }


 // Update is called once per frame
 void Update()
 {



 }

 private IEnumerator HandleStun()
 {
     //Stunned, De activate movement

     playerObject.GetComponent<CharacterHorizontalMovement>().AbilityPermitted = false;
     playerObject.GetComponent<CharacterJump>().AbilityPermitted = false;
     // CharacterHorizontalMovement moveScript = GetComponent<CharacterHorizontalMovement>();
     //  CharacterJump jumpScript = GetComponent<CharacterJump>();

     //  jumpScript.AbilityPermitted = false;
     // moveScript.AbilityPermitted = false;

     // _rigidbody.velocity = new Vector3(0, 0, 0);
     // Vector3 vel = _rigidbody.velocity;
     // vel.z = 0f;
     // _rigidbody.velocity = vel;


     // GameObject.Find("spine-space-cat").SetActive(false);
     // this.gameObject.GetComponent<BoxCollider2D>().enabled = (false);
     // GameObject.Find("spine-space-cat");

     //   if (GameObject.GetComponent <CharacterHorizontalMovement>().WalkSpeed)

     //    if (GameObject.Find("PlayerSpaceship").GetComponent<SpaceshipMovement>().dead == true)



     //Wait for 5 seconds then activate controls
     yield return new WaitForSeconds(StunnedFor);

     playerObject.GetComponent<CharacterHorizontalMovement>().AbilityPermitted = true;
     playerObject.GetComponent<CharacterJump>().AbilityPermitted = true;
     Stunned = false;
     Debug.Log("Start Moving");
     //  jumpScript.AbilityPermitted = true;
     //  moveScript.AbilityPermitted = true;
     Stunned = false;
     //  moveScript.AbilityPermitted = true;
     //  GameObject.Find("Arrows").SetActive(true);
     //  GameObject.Find("ButtonA").SetActive(true);
 }

 void OnTriggerEnter2D(Collider2D col)
 {


     if (col.gameObject.name == "spine-space-cat")
     {
         Debug.Log("Collided with Character FallingObjectcontrol");
         Stunned = true;

     }

 }

}

Now when the item touches my character, the debug log shows as it should, however stunned wasnt getting set to true in the inspector so I changed it to private. Nevertheless, I believe the fixed update is called because "Stunned" is shown in the log. I then attempt to call the coroutine to stun my player for 5 seconds. CharacterHorizontalMovement and CharacterJump is both a script on my player, however, I am unable to set their ability permitted to false even if my code flow seems correct. Interestingly, when I stop my game AbilityPermitted for Characterjump is most times disabled.

So I unsure what I am doing wrong, appreciate if anyone could assist.

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

0 Replies

· Add your reply
  • Sort: 

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

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

ChildsParentObject Function 0 Answers

What to use instead of GameObject.Find and GetComponent 2 Answers

Script getComponent crashes unity. 3 Answers

How to change image of button when clicked? 2 Answers

Get component from parent of children hittet with raycast 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