Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

c# - How to reference TwinCAT.Ads in a Unity Project

Twincat dll is located in "C:Program FilesUnityEditorDataManagedUnityEngine" but it doesn't seem to be added to my project correctly.

This is my code that I want to add the TwinCAT reference into:

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



public class newtest : MonoBehaviour
{
    public InputField Speed;
    public Transform startPos, endPos;
    public bool repeatable = false;
    float startTime, totalDostance;
    
    // Start is called before the first frame update
    void Start()
    {
        ObjectMove();
    }

    IEnumerator ObjectMove()
    {
        float speed = Convert.ToSingle(Speed.text);
        Debug.Log("start");
        startTime = Time.time;
        totalDostance = Vector3.Distance(startPos.position, endPos.position);
        print(repeatable);
        while (repeatable)
        {
            yield return RepeatLerp(startPos.position, endPos.position, 3.0f);
            yield return RepeatLerp(endPos.position, startPos.position, 3.0f);
        }

    }

    // Update is called once per frame
    void Update()
    {
        if (!repeatable)
        {
            float speed = Convert.ToSingle(Speed.text);
            float currentDuration = (Time.time - startTime) * speed;
            float journeyFrraction = currentDuration / totalDostance;
            this.transform.position = Vector3.Lerp(startPos.position, endPos.position, journeyFrraction);

        }
    }
    public IEnumerator RepeatLerp(Vector3 a, Vector3 b, float time)
    {
        float speed = Convert.ToSingle(Speed.text);

        float i = 0.0f;
        float rate = (1.0f / time) * speed;
        while (i < 1.0f)
        {
            i += Time.deltaTime * rate;
            this.transform.position = Vector3.Lerp(a, b, i);
            yield return null;
        }
    }
    public void Click()
    {
      

    }
}

and I try this using alrady but it call "The type or namespace name 'TwinCAT' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp, Assembly-CSharp.Player D:FOR WORKWD projectMR project3DAssets ew test text ewtest.cs 7 Active "

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using TwinCAT.Ads;



public class newtest : MonoBehaviour
{
    public InputField Speed;
    public Transform startPos, endPos;
    public bool repeatable = false;
    float startTime, totalDostance;
    
    // Start is called before the first frame update
    void Start()
    {
        ObjectMove();
    }

    IEnumerator ObjectMove()
    {
        float speed = Convert.ToSingle(Speed.text);
        Debug.Log("start");
        startTime = Time.time;
        totalDostance = Vector3.Distance(startPos.position, endPos.position);
        print(repeatable);
        while (repeatable)
        {
            yield return RepeatLerp(startPos.position, endPos.position, 3.0f);
            yield return RepeatLerp(endPos.position, startPos.position, 3.0f);
        }

    }

    // Update is called once per frame
    void Update()
    {
        if (!repeatable)
        {
            float speed = Convert.ToSingle(Speed.text);
            float currentDuration = (Time.time - startTime) * speed;
            float journeyFrraction = currentDuration / totalDostance;
            this.transform.position = Vector3.Lerp(startPos.position, endPos.position, journeyFrraction);

        }
    }
    public IEnumerator RepeatLerp(Vector3 a, Vector3 b, float time)
    {
        float speed = Convert.ToSingle(Speed.text);

        float i = 0.0f;
        float rate = (1.0f / time) * speed;
        while (i < 1.0f)
        {
            i += Time.deltaTime * rate;
            this.transform.position = Vector3.Lerp(a, b, i);
            yield return null;
        }
    }
    public void Click()
    {
      

    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...