Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm following a unity practice from youtube and seem to have problems at 6:42.
here's the link: https://www.youtube.com/watch?v=gE7gc1sblUA/
and a screenshot:
and the script:
using UnityEngine;
public class player : MonoBehaviour {
public float jumpforce = 10f;
public rigidbody2D rb;
// Update is called once per frame
void Update() {
if (input.GetButtonDown("Jump") || Input.GetMouseButtonDown(0))
{
rb.velocity = Vector2.up * jumpforce;
}
}
}
How can I solve this?
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 days ago.
Improve this question
I am aware this is a novel issue and it is just me either misreading the code or just forgetting a character but I cannot for the life of me figure out where this semi colon is actually meant to go if there even is a need for another one. I get the error stated in the title as well as the lines '(21,10)' but as far as I'm aware, all the correct semi colons are in place. I apologise as this is something I should probably be able to figure out but syntax errors like these seem to be the bane of my existence lately.
Code shown below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
public class EDPathfinding : MonoBehaviour
{
public AIPath aipath;
void Start()
{
}
// Update is called once per frame
void Update()
{
if(aipath.desiredVelocity.x => 0.01f)
{
transform.localScale = new Vector3(-1f, 1f, 1f);
}
else if (aipath.desiredVelocity.x <= -0.01f)
{
transform.localScale = new Vector3(-1f, 1f, 1f);
}
}
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
So i use unity and trying to use Rigidbody scripts and popped up with 5 errors with CS1003.
Heres my code:
using UnityEngine;
public class Movement : MonoBehaviour
void Start ()
rb.useGravity false;
{ public Rigidbody rb;
void Update() {
rb.AddForce(0, 0, 1000*Time.deltaTime);
}
}
I tried putting brackets in certain places but couldnt figure out what to put.
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody rb;
void Start()
{
rb.useGravity = false;
}
void Update()
{
rb.AddForce(0, 0, 1000 * Time.deltaTime);
}
}
I think you want it to look a little like the above.
You are correct that your bracket closure is one of the things stopping Unity from being able to compile your program.
It seems that you are not very familiar with C# syntax in general. I would suggest reading up on these basics, it will greatly help you in developing in Unity.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
I am working on a game made in Unity Engine.
For Movement, I have used vector2. But for vector2, you need to spam the buttons in order for the player to move. So i tried "while" function to loop the process. Here is the main code
if (Input.GetKeyDown(KeyCode.W))
{
i = 5;
}
//test
if (Input.GetKeyUp(KeyCode.W))
{
i = 1;
}
while(i !=1)
{
rb.AddForce(Vector2.up * JumpForce);
}
However, when I run it the engine crashes. Why?
Just to let you know, there are no compiler errors.
In Unity, the physics movement should be done in FixedUpdate, and input checking in Update. Something like this:
[SerializeField] private Rigidbody _rb;
[SerializeField] private float _jumpForce;
private bool _addForce;
private void Update()
{
_addForce = Input.GetKey(KeyCode.W);
}
private void FixedUpdate()
{
if (_addForce) _rb.AddForce(Vector2.up * _jumpForce);
}
If you add a while in the Update, it will stuck in that frame, freezing the main loop, and the engine can't poll for new inputs, so your Update can't continue.
The repeated addforces might be a bit much for the PC.
Do this:
if (Input.GetKey(KeyCode.W))
{
rb.AddForce(Vector2.up * JumpForce);
}
This way it only moves when key is being held.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
This is my complete code, can someone help me.
public float rotationSpeed;
public Transform target, player;
float mouseX, mouseY;
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode; ;
}
void LateUpdate()
{
cameraControl();
}
Assets\ThirPersonCamerController.cs(14,28): error CS0119: 'CursorLockMode' is a type, which is not valid in the given context
You need to pick a lock mode:
Cursor.lockState = CursorLockMode.Locked;
Your choices are None, Locked, and Confined, but Locked seems to best fit your needs. See the Unity reference at https://docs.unity3d.com/ScriptReference/CursorLockMode.html
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want my little cube to change to a bigger one when i click the upper arrow, and change back when i pres the down arrow. I have tried:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSkift : MonoBehaviour {
public gameObject myObject1;
public gameObject myObject2;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.UpArrow))
{
myObject1.SetActive (false);
myObject2.SetActive (true);
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
myObject2.SetActive(false);
myObject1.SetActive(true);
}
}
}
When i try to run it it says:
Assets/PlayerSkift.cs(9,9): error CS0118: `UnityEngine.Component.gameObject' is a `property' but a `type' was expected
I have no idea what that means, so if you know it, or know how to do it in a other way. Please help.
public gameObject myObject1;
public gameObject myObject2;
the above code, as per this discussion, appears to have a typo.
gameObject should be GameObject.