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()
{
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…