Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Syntax error, ',' expected

Discussion in 'Scripting' started by GhoulCody, May 6, 2022.

?

Why doesn't it work?

  1. None

    0 vote(s)
    0.0%
  2. None

    1 vote(s)
    100.0%
  1. GhoulCody

    GhoulCody

    Joined:
    May 2, 2022
    Posts:
    2
    Well, I've tried to write a code that turns on the camera, if it collides with the player. For example, if your player is out of any camera's vision range, it switches to the other camera. Actually, IDK if it works correctly or not, but, anyway, it doesn't work at all. "Assets\ToggleCamera.cs(14,63): error CS1003: Syntax error, ',' expected". Why?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [code=CSharp]public class ToggleCamera : MonoBehaviour
    6. {
    7.  
    8.     public Collider2D player, camera_collider;
    9.  
    10.     public Camera camera;
    11.  
    12.     void Update()
    13.     {
    14.         if(Physics2D.isTouching(Collider2D player, Collider2D camera_collider))
    15.         {
    16.             camera.enabled = true;
    17.         } else
    18.         {
    19.             camera.enabled = false;
    20.         }
    21.     }
    22. }
     
    Last edited: May 6, 2022
  2. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    161
    if (Physics2D.IsTouching(player, camera_collider))
     
    Bunny83 likes this.
  3. GhoulCody

    GhoulCody

    Joined:
    May 2, 2022
    Posts:
    2
    Thanks a lot!