اذهب إلى المحتوى
  • 0

لماذا TouchDist.x و TouchDist.yلا تعمل في هذا الكود

Drox Yf

السؤال

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

public class CameraMove : MonoBehaviour
{
   public float Yaxis;
   public float Xaxis;
   public float RotationSensitivity = 8f;
   public Transform target;
    float RotationMin = -40;
    float RotationMax = 80f;
    float smoothTime = 0.12f;

   Vector3 targetRotation;
   Vector3 currentVel;
   public  bool enableMobileInputs = false;
   public FixedTouchField touchField;

   
    void LateUpdate()
    {
        if (enableMobileInputs)
        {
          Yaxis += touchField.TouchDist.x * RotationSensitivity;
          Xaxis -= touchField.TouchDist.y * RotationSensitivity;
        }
        else
        {

        
        Yaxis += Input.GetAxis("Mouse X")* RotationSensitivity;
        Xaxis -= Input.GetAxis("Mouse Y")* RotationSensitivity;
        }
        Xaxis = Mathf.Clamp(Xaxis, RotationMin, RotationMax);

        targetRotation = Vector3.SmoothDamp(targetRotation, new Vector3(Xaxis, Yaxis), ref currentVel, smoothTime);

        transform.eulerAngles = targetRotation;
       
       transform.position = target.position - transform.forward * 2f;

    }
}

انا ابرمج هدا الكود بلغة #c و كنت اتبع فيديو وعندما وصلت لل TouchDist.x و TouchDist.y  ارى ان هناك خطا ولا اعرف لمادا اتمنى ان يساعدني احد ما 

تم التعديل في بواسطة Mustafa Suleiman
تعديل عنوان السؤال
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

يمكن أن يكون الخطأ الذي تشير إليه مرتبط بـ FixedTouchField الذي يتم استخدامه في الكود والذي لا يتم تعريفه في الكود المرفق. ومن المحتمل أيضًا أن يكون هذا الكود ليس متوافقًا مع إصدار Unity الذي تستخدمه حاليًا.

يتم استخدام FixedTouchField في هذا الكود للتحكم بحركة الكاميرا باستخدام إدخالات اللمس على الهواتف النقالة. ومن المحتمل أن يكون الخطأ الذي تواجهه مرتبطًا بهذا المتغير.

إذا كان الخطأ مرتبطًا بـ FixedTouchField، يرجى التحقق من ما إذا كانت المكتبة المستخدمة لـ FixedTouchField تم تضمينها بشكل صحيح في مشروع Unity الخاص بك، وهل تم تعيين الكائن touchField الخاص بـ FixedTouchField بشكل صحيح في المحرر.

تعديل الكود بهذا الشكل قد يكون حلاً لهذه المشكلة:

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

public class CameraMove : MonoBehaviour
{
   public float Yaxis;
   public float Xaxis;
   public float RotationSensitivity = 8f;
   public Transform target;
   float RotationMin = -40;
   float RotationMax = 80f;
   float smoothTime = 0.12f;

   Vector3 targetRotation;
   Vector3 currentVel;
   public bool enableMobileInputs = false;
   public FixedTouchField touchField;
   
    void LateUpdate()
    {
        if (enableMobileInputs && touchField != null)
        {
          Yaxis += touchField.TouchDist.x * RotationSensitivity;
          Xaxis -= touchField.TouchDist.y * RotationSensitivity;
        }
        else
        {
          Yaxis += Input.GetAxis("Mouse X") * RotationSensitivity;
          Xaxis -= Input.GetAxis("Mouse Y") * RotationSensitivity;
        }
        
        Xaxis = Mathf.Clamp(Xaxis, RotationMin, RotationMax);

        targetRotation = Vector3.SmoothDamp(targetRotation, new Vector3(Xaxis, Yaxis), ref currentVel, smoothTime);

        transform.eulerAngles = targetRotation;
        transform.position = target.position - transform.forward * 2f;
    }
}

في هذا الكود، تم إضافة شرط للتحقق من وجود touchField وأنه غير مساوٍ للقيمة null قبل استخدامه في حركة الكاميرا عند تمكين enableMobileInputs. ويتم التحقق من ذلك باستخدام العامل اللوجيكي && لإجراء اختبار مزدوج.

كما يمكنك التحقق من الرسائل التي يتم عرضها في لوحة التحكم Console في Unity لمعرفة مزيد من المعلومات حول الخطأ الذي تواجهه. وفي حالة وجود رسائل خطأ، يمكنك مشاركتها معنا هنا لتمكيننا من تقديم المساعدة المناسبة.

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0

يبدو أن هناك خطأ في الكود بالفعل. يتم استخدام TouchDist في الشفرة، وهو متغير غير معرف في الفئة CameraMove. ربما كان المقصود هو استخدام TouchField للحصول على البيانات المتعلقة باللمس.

لتصحيح الكود، يجب تحديد TouchField كمتغير عام (public) في الفئة CameraMove، ثم استخدامه للحصول على القيم المتعلقة باللمس، كما هو موضح في الكود المعدل أدناه:

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

public class CameraMove : MonoBehaviour
{
   public float Yaxis;
   public float Xaxis;
   public float RotationSensitivity = 8f;
   public Transform target;
    float RotationMin = -40;
    float RotationMax = 80f;
    float smoothTime = 0.12f;

   Vector3 targetRotation;
   Vector3 currentVel;
   public bool enableMobileInputs = false;
   public FixedTouchField touchField;

   
    void LateUpdate()
    {
        if (enableMobileInputs)
        {
          Yaxis += touchField.TouchDist.x * RotationSensitivity;
          Xaxis -= touchField.TouchDist.y * RotationSensitivity;
        }
        else
        {
          Yaxis += Input.GetAxis("Mouse X")* RotationSensitivity;
          Xaxis -= Input.GetAxis("Mouse Y")* RotationSensitivity;
        }
        Xaxis = Mathf.Clamp(Xaxis, RotationMin, RotationMax);

        targetRotation = Vector3.SmoothDamp(targetRotation, new Vector3(Xaxis, Yaxis), ref currentVel, smoothTime);

        transform.eulerAngles = targetRotation;
       
       transform.position = target.position - transform.forward * 2f;

    }
}

تم تحديد touchField كمتغير عام واستخدامه للحصول على TouchDist.x و TouchDist.y. يجب التأكد من أنه تم إضافة FixedTouchField إلى المشهد وتعيينه في متغير touchField في محرر Unity.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 16 ساعة قال بلال زيادة:

لتصحيح الكود، يجب تحديد TouchField كمتغير عام (public) في الفئة CameraMove، ثم استخدامه للحصول على القيم المتعلقة باللمس، كما هو موضح في الكود المعدل أدناه:

 
بتاريخ 16 ساعة قال بلال زيادة:

كيف اضيفTouchField كمتغير عام

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 21 ساعة قال أحمد رضا5:

يمكن أن يكون الخطأ الذي تشير إليه مرتبط بـ FixedTouchField الذي يتم استخدامه في الكود والذي لا يتم تعريفه في الكود المرفق. ومن المحتمل أيضًا أن يكون هذا الكود ليس متوافقًا مع إصدار Unity الذي تستخدمه حاليًا.

يتم استخدام FixedTouchField في هذا الكود للتحكم بحركة الكاميرا باستخدام إدخالات اللمس على الهواتف النقالة. ومن المحتمل أن يكون الخطأ الذي تواجهه مرتبطًا بهذا المتغير.

إذا كان الخطأ مرتبطًا بـ FixedTouchField، يرجى التحقق من ما إذا كانت المكتبة المستخدمة لـ FixedTouchField تم تضمينها بشكل صحيح في مشروع Unity الخاص بك، وهل تم تعيين الكائن touchField الخاص بـ FixedTouchField بشكل صحيح في المحرر.

تعديل الكود بهذا الشكل قد يكون حلاً لهذه المشكلة:

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

public class CameraMove : MonoBehaviour
{
   public float Yaxis;
   public float Xaxis;
   public float RotationSensitivity = 8f;
   public Transform target;
   float RotationMin = -40;
   float RotationMax = 80f;
   float smoothTime = 0.12f;

   Vector3 targetRotation;
   Vector3 currentVel;
   public bool enableMobileInputs = false;
   public FixedTouchField touchField;
   
    void LateUpdate()
    {
        if (enableMobileInputs && touchField != null)
        {
          Yaxis += touchField.TouchDist.x * RotationSensitivity;
          Xaxis -= touchField.TouchDist.y * RotationSensitivity;
        }
        else
        {
          Yaxis += Input.GetAxis("Mouse X") * RotationSensitivity;
          Xaxis -= Input.GetAxis("Mouse Y") * RotationSensitivity;
        }
        
        Xaxis = Mathf.Clamp(Xaxis, RotationMin, RotationMax);

        targetRotation = Vector3.SmoothDamp(targetRotation, new Vector3(Xaxis, Yaxis), ref currentVel, smoothTime);

        transform.eulerAngles = targetRotation;
        transform.position = target.position - transform.forward * 2f;
    }
}

في هذا الكود، تم إضافة شرط للتحقق من وجود touchField وأنه غير مساوٍ للقيمة null قبل استخدامه في حركة الكاميرا عند تمكين enableMobileInputs. ويتم التحقق من ذلك باستخدام العامل اللوجيكي && لإجراء اختبار مزدوج.

كما يمكنك التحقق من الرسائل التي يتم عرضها في لوحة التحكم Console في Unity لمعرفة مزيد من المعلومات حول الخطأ الذي تواجهه. وفي حالة وجود رسائل خطأ، يمكنك مشاركتها معنا هنا لتمكيننا من تقديم المساعدة المناسبة.

 

في اليونتي :

Assets\Scripts\CameraMove.cs(26,41): error CS1061: 'object' does not contain a definition for 'x' and no accessible extension method 'x' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

 

ssets\Scripts\CameraMove.cs(27,41): error CS1061: 'object' does not contain a definition for 'y' and no accessible extension method 'y' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

في الفيجيوال ستوديو كود:

object' does not contain a definition for 'x' and no accessible extension method 'x' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]csharp(CS1061)

ssets\Scripts\CameraMove.cs(27,41): error CS1061: 'object' does not contain a definition for 'y' and no accessible extension method 'y' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

هدا هو الخطا الدي يظهر لي 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 2 ساعة قال Drox Yf:

في اليونتي :

Assets\Scripts\CameraMove.cs(26,41): error CS1061: 'object' does not contain a definition for 'x' and no accessible extension method 'x' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

 

ssets\Scripts\CameraMove.cs(27,41): error CS1061: 'object' does not contain a definition for 'y' and no accessible extension method 'y' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

في الفيجيوال ستوديو كود:

object' does not contain a definition for 'x' and no accessible extension method 'x' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]csharp(CS1061)

ssets\Scripts\CameraMove.cs(27,41): error CS1061: 'object' does not contain a definition for 'y' and no accessible extension method 'y' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

هدا هو الخطا الدي يظهر لي 

 المشكلة في استخدام المتغير TouchDist كـ "object" بدلاً من استخدامه كـ "Vector2". يجب التأكد من أن المتغير TouchDist من نوع Vector2. وللتأكد من ذلك ، يمكنك التحقق من الكلاس FixedTouchField والتحقق من أن تحديث المتغير TouchDist يتم باستخدام Vector2 وليس object. وقد يكون هذا الخطأ قد ظهر بسبب تغيير نوع المتغير في وقت لاحق في الكود.

 TouchDist هو كائن من النوع object ولا يحتوي على خصائص x و y كما هو متوقع. فيجب تحويل TouchDist إلى النوع المناسب لهذه الخصائص.

وفي هذه الحالة، على الأرجح أن FixedTouchField هو الكائن الذي يتم تمرير TouchDist إليه. لذلك، يجب التأكد من أن FixedTouchField يحتوي على خصائص x و y المطلوبة.

ويمكنك تجربة تغيير السطر التالي:

Yaxis += touchField.TouchDist.x * RotationSensitivity;
Xaxis -= touchField.TouchDist.y * RotationSensitivity;

إلى:

Yaxis += touchField.TouchDist.normalized.x * RotationSensitivity;
Xaxis -= touchField.TouchDist.normalized.y * RotationSensitivity;

بتحويل TouchDist إلى نوع Vector2 باستخدام الخاصية normalized التي تعيد قيمة Vector2 مع محافظة الاتجاه الأصلي ولكن بقيمة طول تمثيلي يساوي 1.0. بعد ذلك، يمكن استخدام خصائص x و y بشكل صحيح.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...