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 Supermacka · Feb 26, 2018 at 05:35 PM · not workingroll a balladvice

Problem with adding a obstacle to "Roll a Ball" tutorial

Hi, I recently finished the "Roll a Ball" tutorial from unity's tutorial videos and so thought, maybe I could develop the game some more by adding a spinning wall (to jump over) that kills you when you get in contact whith it. When writing the code for picking up the objects I made a mistake which made the character disappear instead of the objects:

     void OnCollisionEnter (Collider other)
     {
        if (other.gameObject.CompareTag("Pick Up"))
         {
             gameObject.SetActive(false);
         }
     }
 }

so i figured maybe I can use this failure for creating my obstacle. I added the code to the playerScript and added the necessary tags to the objects in the scene. But for some reason it is not working the way I want it to:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
     public float speed;
     public float jumpPower;
     private Rigidbody rb;
     private int count;
     public Text countText;
     public Text winText;
 
     // Use this for initialization
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         count = 0;
         SetCountText();
         winText.text = "";
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
 
         if (Input.GetKey(KeyCode.Space) && rb.transform.position.y <= 0.6250001f)
         {
             Vector3 jumping = new Vector3(0, 10, 0);
             rb.AddForce(jumping * jumpPower * Time.deltaTime);
         }
 
         rb.AddForce(movement * speed * Time.deltaTime);
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag("Pick Up"))
         {
             other.gameObject.SetActive(false);
             count = count +100;
             SetCountText();
         }         
     }
 
     void SetCountText()
     {
         countText.text = "Count: " + count.ToString() + "p";
         if (count >=1100)
         {
             winText.text = "Winner!";
         }
     }
 
     void OnCollisionDie(Collider other)
     {
         if (other.gameObject.CompareTag("DeathCube"))
         {
             gameObject.SetActive(false);
         }
     }
 }

If I set the "Player" to "Is Trigger" it will fall through everything, but if I in the other hand set my object named "DeathCube to "IsTriggered the player just falls through the it and nothing more happens, no disapearing.

I should probably mention that i made a working project where the player rolls in to a wall and disappeares.

How do you fix this problem or add this kind of death-obstacle to the game?

Thanks in advance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Chik3r · Feb 26, 2018 at 08:17 PM

Hi @Supermacka First of all: What is 'OnCollisionDie' or when are you calling it? Because that function isn't called when you collide nor when you touch a trigger. What I think you want is to use 'OnCollisionEnter(Collider other)' and that way when you collide with the DeathCube you instantly deactivate

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 Supermacka · Feb 26, 2018 at 08:36 PM

@chiker Thank you so much! I didn't know "OnCollisionEnter" was a funtion, i just thought you name your "void" whatever you want, in my case "OnCollisionDie".

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

77 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

Related Questions

roll the ball collecting cubes not working help 4 Answers

Does anyone understand why I keep getting "ArgumentOutOfRangeException" from my code? 0 Answers

Play audio once not working 0 Answers

my car rolls over to the right always when i run the game and wheels fly away from the car, 2 Answers

Why does the sprite editor not slice the sprite sheet? 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