K
K
KraGen.Developer2021-08-30 14:08:29
Unity
KraGen.Developer, 2021-08-30 14:08:29

Error CS1061: 'Vector3' does not contain a definition for 'transform' and no accessible extension method 'transform how to fix?

How can I fix this code so that it works?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerST : MonoBehaviour
{
    public GameObject camera;
    public float speed = 20f;
    public Joystick joystick;
    Rigidbody  rb;
    // Start is called before the first frame update
    void Start()
    {
        rb= GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    void FixedUpdate(){
        rb.AddForce(camera.transform.forward * joystick.Vertical * speed, 0f, camera.transform.right * joystick.Horizontal * speed);
    }
}


The script is hung on the sphere (player) and, in theory, the player should move along the camera's view vector.
BUT I get an error: Assets\Scripts\PlayerST.cs(23,86): error CS1061: 'Vector3' does not contain a definition for 'transform' and no accessible extension method 'transform' accepting a first argument of type 'Vector3' could be found (are you missing a using directive or an assembly reference?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-08-30
@KraGenDeveloper

Understand the arguments AddForce, you have porridge there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question