M
M
Max Bogachov2017-03-18 17:46:59
2D
Max Bogachov, 2017-03-18 17:46:59

How to fix CS0119?

I made a rotation, but for some reason it gives an error

Assets/Scripts/moving.cs(22,24): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moving : MonoBehaviour {
  public GameObject obj;
  private float speed = 5f,rotSpeed = 2f;
  private Rigidbody2D rb;
  private SpriteRenderer spr;
  float rotation;

  private void Awake(){
    rb = GetComponent  ();
    spr = GetComponent  ();
  }

  private void Run(){
    rotation = rotSpeed * Input.GetAxis("Horizontal");
    if (Input.GetAxis ("Horizontal") == 1f || Input.GetAxis("Horizontal") == -1f) {
      rotation =+ rotSpeed;
    }
    transform.rotation = Quaternion (new Vector3 (transform.rotation, transform.rotation, rotation));
    Vector3 direction = transform.up * Input.GetAxis ("Vertical");
    transform.position = Vector3.MoveTowards (transform.position, transform.position + direction,speed * Time.deltaTime);
  }

  private void Update () {
    Run ();
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2017-03-18
@Geekinder

And now to the point.
transform.rotation = Quaternion(new Vector3(transform.rotation, transform.rotation, rotation));
You CREATE an object of type Quaternion , and when creating objects, new is used (memory allocation, etc., etc.).
i.e. it should be
transform.rotation = new Quaternion (new Vector3 (transform.rotation, transform.rotation, rotation));
If, after all, you are not using a newly created object, but just want a method over a quaternion , then it would be
Quaternion.DesiredMethod(method parameters). and in your case, you try to use the object constructor (parameters for it) without selecting the object as such. A lot
of repetitions and so on, but I repeat - you would have some course "Programming Fundamentals" without fail

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question