i am having this error while creating script file in c#
Assets/scripts/Player.cs(7,14): error CS0029: Cannot implicitly convert type UnityEngine.Rigidbody[ ]' to UnityEngine.Rigidbody’
here is my code
using UnityEngine;
using System.Collections;
public class playerControler : MonoBehaviour {
public Rigidbody rb;
void start(){
rb = GetComponents ();
}
void fixedupdate(){
float moveHorizontal = Input.GetAxis(“Horizontal”);
float moveVertical = Input.GetAxis(“Vertical”);
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement);
}
}
plz give me some suggestions
1 Like
Kiwasi
November 4, 2015, 11:42am
2
Change GetComponents to GetComponent
13 Likes
@Kiwasi
thnx for the suggestion. its working .
thnx a lot
2 Likes
oh my gosh , you solve my problem. damm autoinsert…
thanks !!!
1 Like
thank you brother you solve my problem…
Just gonna go ahead and post this picture every time it happens.
1 Like
Thanks so much, my problem solved too
i m also having this problem my code is
plz tell me any solution
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControls : MonoBehaviour
{
public KeyCode moveUp = KeyCode.W;
public KeyCode moveDown = KeyCode.S;
public float speed = 10.0f;
public float boundY = 2.25f;
private Rigidbody rb2d;
void Start()
{
rb2d = GetComponent();
}
void Update()
{
var vel = rb2d.velocity;
if (Input.GetKey(moveUp))
{
vel.y = speed;
}
else if (Input.GetKey(moveDown))
{
vel.y = -speed;
}
else
{
vel.y = 0;
}
rb2d.velocity = vel;
var pos = transform.position;
if(pos.y > boundY)
{
pos.y = boundY;
}
else if(pos.y < -boundY)
{
pos.y = -boundY;
}
transform.position = pos;
}
}
AriyaSD
November 5, 2020, 7:58am
10
SpideyBurhan:
i m also having this problem my code is
plz tell me any solution
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControls : MonoBehaviour
{
public KeyCode moveUp = KeyCode.W;
public KeyCode moveDown = KeyCode.S;
public float speed = 10.0f;
public float boundY = 2.25f;
private Rigidbody rb2d;
void Start()
{
rb2d = GetComponent();
}
void Update()
{
var vel = rb2d.velocity;
if (Input.GetKey(moveUp))
{
vel.y = speed;
}
else if (Input.GetKey(moveDown))
{
vel.y = -speed;
}
else
{
vel.y = 0;
}
rb2d.velocity = vel;
var pos = transform.position;
if(pos.y > boundY)
{
pos.y = boundY;
}
else if(pos.y < -boundY)
{
pos.y = -boundY;
}
transform.position = pos;
}
}
change the line
private Rigidbody rb2d;
to
private Rigidbody2D rb2d;
2 Likes
Hi Guys can you please help me this is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Obstacle : MonoBehaviour
{
public float speed = -1f;
private Rigidbody myRB;
// Use for Initialization
void Start (){
myRB = GetComponent ();
}
// Update is called once per frame
void Update()
{
myRB.velocity = new Vector2 (speed, 0);
}
}
The error code is :
error CS0029: Cannot implicitly convert type ‘UnityEngine.Rigidbody2D’ to ‘UnityEngine.Rigidbody’
Don’t reply to 5-year-old irrelevant posts. Instead, create your own fresh post. It’s FREE!
When you do, keep several things in mind:
How to report your problem productively in the Unity3D forums:
http://plbm.com/?p=220
Please use code tags: https://discussions.unity.com/t/481379
1 Like
hello guys. Can you help me please, the error is: Assets\scripts\script.cs(12,14): error CS0029: Cannot implicitly convert type ‘float’ to ‘UnityEngine.Rigidbody’
here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DisminuirVelocidadDeFuerzaTrasImpacto : MonoBehaviour
{
public Rigidbody rg;
void Start()
{
rg = GetComponent().mass = 0.4f;
}
}
alejollamon08:
Can you help me please
Please read my post immediately above yours.
Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
The important parts of an error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
How to understand compiler and other errors and even fix them yourself:
https://forum.unity.com/threads/assets-mouselook-cs-29-62-error-cs1003-syntax-error-expected.1039702/#post-6730855