public int num; //The value will change
int numCopy;
void Update ()
{
//method 1
if (numCopy != num)
{
numCopy = num;
}
//method 2
numCopy = num;
}
public int num; //The value will change
int numCopy;
void Update ()
{
//method 1
if (numCopy != num)
{
numCopy = num;
}
//method 2
numCopy = num;
}
Without knowing use case and any other parts of your code Method2 is more efficient (if efficiency is based on number of instructions), because both will want to end up having those two integers having the same value, therefore the if condition is unnecessary.
Now I believe primitives can be accessed within one cycle, if not it would not matter in this scenario anyway, but it means that checking for “if” condition first then assigning can take 2 cycles or in somecases 1 if stored correctly. Meaning it can possibly double the computational power needed.
Hope this helps