Question by
loijac2018 · Jan 03 at 05:05 PM ·
scripting problemerror messagereferencinggame development
Referencing and Executing Script Can't Be Done due to Not Being A Statement
I keep getting an error CS0201 on the lines (31,13). It says that only assignment, call, increment, decrement, await, and new object expressions can be used as a statement. If I were to just put in the variable reference by itself, it shows no errors but it doesn't execute the referenced code. How can I reference the other script in the same game object as the one shown?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
Vector2 mousePos;
public Camera cam;
public Shooting shooting;
// Start is called before the first frame update
void Start()
{
shooting = GetComponent<Shooting>();
}
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetButtonDown("Fire1"))
{
shooting;
}
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
Vector2 lookDir = mousePos - rb.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
rb.rotation = angle;
}
}
Comment