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 Joebear · Dec 16, 2015 at 02:36 AM · c#errorrigidbodycollider

AddRigidBody Script Error

I have an AddRigidBody script for an FPS zombie game, and it has this error. I'm not even really sure what this means, nor can I find it anywhere on the internet. The error: " Assets/Scripts/AddRigidBody.cs(8,17): error CS0029: Cannot implicitly convert type UnityEngine.Rigidbody' to AddRigidbody' " And my script:

 using UnityEngine;
 using System.Collections;
 
 public class AddRigidbody: MonoBehaviour {
     public float mass;
     public AddRigidbody rb;
     void Start() {
         rb = GetComponent<Rigidbody>();
         rb.mass = mass;
     }
 }


Just to clear it up, both of the objects have non-trigger collisions. The object is a zombie and the second object is a wall. They just kind of go right through the walls, instead of stopping like the Player. Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Firedan1176 · Dec 16, 2015 at 05:01 AM

On line 6, you are trying to set your gameObject's Rigid body as an AddRigidBody, so you shold change that line to public Rigidbody rb;. I'm not sure if you're familiar with objects, but when you create a class, you can create a new object (which isn't Unity specific, like GameObject), which is why you would use new GameObject () or in your case, new AddRigidBody (), so I hope this clears some things up for you.

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 Firedan1176 · Dec 16, 2015 at 05:03 AM 0
Share

The error essentially means that the data types aren't the same, and Unity is not able to convert them (for example, float to a double or even a string).

avatar image Joebear Firedan1176 · Dec 16, 2015 at 11:43 PM 0
Share

I fixed the error, but I can't add the component. It says I need a valid script. Your comment did help me a lot, thank you! But I still can't assess the script onto the enemy. There are no errors in the log, and the file name and script class are the same. I'm not sure what's causing this. Or is this a different question to be posted? Thank you for your input, though!

avatar image Soraphis Joebear · Dec 16, 2015 at 11:51 PM 0
Share

you should update your script in the post (or add how it looks now) because if your script is invalid we cant help you without seeing the script.

from what Firedan1176 said it should look like:

 using UnityEngine;
 using System.Collections;

 public class AddRigidbody: $$anonymous$$onoBehaviour {
     public float mass;
     public Rigidbody rb;
     void Start() {
         rb = GetComponent<Rigidbody>();
         rb.mass = mass;
     }
 }
Show more comments
Show more comments

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

47 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

Related Questions

Why Does A Rigidbody Affect Enemy Health? 1 Answer

error CS0103 rb doesn't exist in the current context, ligne 8 and 15 , can't fix it 1 Answer

How to move an object able to collide through something outside of physics? 0 Answers

Freeze rotation of just the box collider component 0 Answers

How to fix this problem? 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