Question by
Empiregaming · Jul 10, 2017 at 06:30 PM ·
positionprefabsclassclass objectfauxgravity
cannot drag and assign other class from script to prefab
Hi i am new to unity and trying to create an asteroid and planet game . The asteroid is a prefab with fauxGravityBody script and has a class (Public GravityAttractor attractor ) which gives me space in inspector to add my planet ....the script works fine when the asteroid prefab is a gameobject but as soon as i drag it to prefab ,i am not allowed to assign my planet to it. Please help me ...check my code.
FauxBodyAttractor code:-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FauxGravityBody : MonoBehaviour {
public GravityAttractor attractor;
private Transform myTransform;
void Start()
{
GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
GetComponent<Rigidbody>().useGravity = false;
myTransform = transform;
}
void Update()
{
attractor.Attract(myTransform);
}
}
@OperationDogBird
prefab-problem.png
(158.8 kB)
Comment
Your answer
Follow this Question
Related Questions
Accessing Nested Class Information 1 Answer
How get position from a prefab? 0 Answers
Custom class, Null Reference Exception 4 Answers
connect 3 gameobjects 0 Answers
Way to copy a Class without copying the references? 0 Answers