Cannot implicitly convert type `UnityEngine.Quaternion' to `UnityEngine.Transform'

I want to rotate an animated npc character

I’m using:

using UnityEngine;
using System.Collections;

public class Vira : MonoBehaviour {
	
	public float counter;
	
	public Transform from;
	public Transform to;
	public float speed = 0.1F;

	
	void Update () 
	{
	
		from = transform.rotation;
		to = new Quaternion(transform.rotation.x, transform.rotation.y + 180, transform.rotation.z, transform.rotation.w);
		transform.rotation = Quaternion.Slerp(from.rotation, to.rotation, Time.deltaTime * speed);
       }
}

Its giving me an error:

Assets/Vira.cs(16,17): error CS0029: Cannot implicitly convert type UnityEngine.Quaternion' to UnityEngine.Transform’

Why ? If i’m using transform.rotation this would works

1 Answer

1

In your code, you made from and to transforms (lines 8-9).

In lines 16-17, you are trying to put quaternions in those transforms.

You should make from and to quaternions instead of transforms (change Transform to Quaternion in lines 8-9).